Is this a bug in __traits(hasMember..)?

Tobias Pankrath tobias at pankrath.net
Tue Nov 8 12:09:00 PST 2011


Please take a look at this code

--------------------
struct Bag(S...)
{
    alias S Types;
}

template Test(alias i, B)
{
    void fn() {
        foreach(t; B.Types)
        {
            switch(i) {
                case IndexOf!(t, B.Types):
                {
                    pragma(msg, __traits(allMembers, t));
                    pragma(msg, __traits(hasMember, t, "m"));
                    break;
                }
                default: {}
            }

        }
    }
}

struct A
{
    int m;
}


void main()
{

    int i;
    alias Test!(i, Bag!(A)).fn func;
}
-----------------

If I compile this, DMD will print
------------------
dmd test.d 
tuple("m")
false
------------------

which is very confusing to me. Guess this is a bug?

Tobias


More information about the Digitalmars-d-learn mailing list