[Issue 17545] [REG2.072] __traits(getAttributes, name) evaluates name to value prematurely

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Jun 24 10:58:44 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17545

--- Comment #2 from monkeyworks12 at hotmail.com ---
If you don't want to modify the enum the following code also seems to work. The
main thing is to avoid using __traits(getMember) which could get passed a
non-symbol.

module example;
import std.meta: staticIndexOf;
import std.traits;

struct Attrib {}

@Attrib enum TEST = 123;

void foo() {
    foreach(sym; getSymbolsByUDA!(example, Attrib)) {
        pragma(msg, sym.stringof); //Prints 123
    }
}

The fact that it prints 123 instead of TEST seems to suggest that it is indeed
a problem with the compiler pasting the value where the identifier is used. I'd
recommend taking a look at the implementation of getSymbolsByUDA to see how
it's done there.

--


More information about the Digitalmars-d-bugs mailing list