Can't get UDAs of constants (enums) !

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 24 17:16:15 PDT 2017


On 24.06.2017 19:42, Johan Engelen wrote:
> This code no longer compiles (regression since 2.072, [1]):
> ```
> module example;
> import std.meta: staticIndexOf;
> 
> struct Attrib {}
> 
> @Attrib enum TEST = 123;
> 
> void foo() {
>      foreach(name; __traits(allMembers, example)) {
>          pragma(msg, name);
>          pragma(msg, __traits(getAttributes, __traits(getMember, 
> example, name)));
>      }
> }
> ```
> 
> Does anybody know a workaround? (the intent is to loop over all module 
> members that have a certain UDA applied)
> It's currently blocking Weka from updating to a newer compiler. :(
> 
> You can play with code live here: https://godbolt.org/g/G8Yw59
> Switch between LDC 1.1.0 (dlang 2.071) and LDC 1.2.0 (dlang 2.072).
> 
> Thanks,
>    Johan
> 
> [1]  https://issues.dlang.org/show_bug.cgi?id=17545
> 
> 


FWIW: This seems to fix the problem:
https://github.com/dlang/dmd/compare/master...tgehr:fix17545

I don't really understand why though.


More information about the Digitalmars-d mailing list