digitalmars.D - deprecated enum and to!string warnings
- Vladimirs Nordholm (11/11) Nov 19 2018 The following code produces 28 deprecation warnings at build time:
- Jonathan M Davis (17/28) Nov 19 2018 You're going to get a deprecation message every time baz is used, and in
- Vladimirs Nordholm (8/25) Nov 19 2018 Thank you for your answer Jonathan.
- Steven Schveighoffer (9/25) Nov 19 2018 Ouch!
- Vladimirs Nordholm (4/31) Nov 19 2018 Yeah, looking at the source code I can see EnumMembers! being
The following code produces 28 deprecation warnings at build time: import std.conv : to; enum Foo { bar, deprecated baz } void main() { to!string(Foo.bar); } Why is that? https://run.dlang.io/is/AdUscN
Nov 19 2018
On Monday, November 19, 2018 12:47:44 PM MST Vladimirs Nordholm via Digitalmars-d wrote:The following code produces 28 deprecation warnings at build time: import std.conv : to; enum Foo { bar, deprecated baz } void main() { to!string(Foo.bar); } Why is that? https://run.dlang.io/is/AdUscNYou're going to get a deprecation message every time baz is used, and in order for to!string to do its thing, it uses it in a bunch of places internally. Glancing at the output there, it does look like the messages are doubled up for some reason, with each line being listed twice, which is a bit odd, and I'd have to do some digging to see why that is happening, but the fact that you're getting multiple deprecation messages is not surprising considering that you're compiling a templated function that is using a deprecated symbol. If you were calling a non-templated function, then you would just get a deprecation message at the call point, but you're calling a templated function that's then doing type introspection on the deprecated symbol, so it refers to it a lot internally. Also, FYI, please ask questions about learning D in the D.Learn newsgroup / forum, not the general newsgroup / forum. This is for general discussion on D, not for asking questions on how to use D or how it works. - Jonathan M Davis
Nov 19 2018
On Monday, 19 November 2018 at 21:03:31 UTC, Jonathan M Davis wrote:On Monday, November 19, 2018 12:47:44 PM MST Vladimirs Nordholm via Digitalmars-d wrote:Thank you for your answer Jonathan. And yes, I realised after posting that D.Learn would be a better place for this type of question. Will keep this in mind until next time :-) Best regards, Vladimirs Nordholm[...]You're going to get a deprecation message every time baz is used, and in order for to!string to do its thing, it uses it in a bunch of places internally. Glancing at the output there, it does look like the messages are doubled up for some reason, with each line being listed twice, which is a bit odd, and I'd have to do some digging to see why that is happening, but the fact that you're getting multiple deprecation messages is not surprising considering that you're compiling a templated function that is using a deprecated symbol. If you were calling a non-templated function, then you would just get a deprecation message at the call point, but you're calling a templated function that's then doing type introspection on the deprecated symbol, so it refers to it a lot internally. [...]
Nov 19 2018
On 11/19/18 2:47 PM, Vladimirs Nordholm wrote:The following code produces 28 deprecation warnings at build time: import std.conv : to; enum Foo { bar, deprecated baz } void main() { to!string(Foo.bar); } Why is that? https://run.dlang.io/is/AdUscNOuch! I don't know if there's a way to fix this, what I think is happening is there are multiple instantiations of the same template from different places, and each time it's used, it's going to cause a warning. The reason you see it, even though "baz" isn't used, is likely because of the way to!string works for enums (it probably uses a switch with all the enum values as cases). -Steve
Nov 19 2018
On Monday, 19 November 2018 at 21:04:02 UTC, Steven Schveighoffer wrote:On 11/19/18 2:47 PM, Vladimirs Nordholm wrote:Yeah, looking at the source code I can see EnumMembers! being called, so I'll just have to work around itThe following code produces 28 deprecation warnings at build time: import std.conv : to; enum Foo { bar, deprecated baz } void main() { to!string(Foo.bar); } Why is that? https://run.dlang.io/is/AdUscNOuch! I don't know if there's a way to fix this, what I think is happening is there are multiple instantiations of the same template from different places, and each time it's used, it's going to cause a warning. The reason you see it, even though "baz" isn't used, is likely because of the way to!string works for enums (it probably uses a switch with all the enum values as cases). -Steve
Nov 19 2018