I'm not sure if this is a bug or not.

I was playing around with printing out some member types with unittests and I was noticing some strange results when they were in @safe unittests rather than normal unittests. The first one prints out what I would expect, but the @safe unittest puts @safe @nogc nothrow and pure on them, as if it is re-writing the struct as a template (or maybe just the functions as templates, I don't know).

private enum isPrivate(T, string member) = !__traits(compiles, __traits(getMember, T, member));

void printMemberTypes(alias T)()
{
    foreach(memberName; __traits(allMembers, T))
    {
        static if(!isPrivate!(T, memberName)) {
writeln(typeid(typeof(__traits(getMember, T, memberName))));
        }
    }
}

unittest
{
    struct Foo {
        int foo(int i, string s) @safe { return 0; }
        double foo2(string s) @safe { return 0; }
    }

    printMemberTypes!(Foo);
}

@safe unittest
{
    struct Foo {
        int foo(int i, string s) @safe { return 0; }
        double foo2(string s) @safe { return 0; }
    }

    printMemberTypes!(Foo);
}

Reply via email to