www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - deprecated enum and to!string warnings

reply Vladimirs Nordholm <v vladde.net> writes:
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
next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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/AdUscN
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. 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
parent Vladimirs Nordholm <v vladde.net> writes:
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:
 [...]
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. [...]
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
Nov 19 2018
prev sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
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/AdUscN
Ouch! 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
parent Vladimirs Nordholm <v vladde.net> writes:
On Monday, 19 November 2018 at 21:04:02 UTC, Steven Schveighoffer 
wrote:
 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/AdUscN
Ouch! 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
Yeah, looking at the source code I can see EnumMembers! being called, so I'll just have to work around it
Nov 19 2018