static weirdness

Alex sascha.orlov at gmail.com
Wed Jan 24 01:48:45 UTC 2018


the story of
https://forum.dlang.org/thread/qknxjxzbaowmsjdngvli@forum.dlang.org
continues

How can this be?

void main()
{
     auto s = S();
     auto t = T!s();
     assert(typeof(t).dummy == null);
     assert(t.dummy == null);
     t.foo;

}

struct S
{
     auto fun()
     {
     	return 42;
     }
}

struct T(alias stats)
{
     static typeof(stats)* dummy; // line 21
     static auto foo()
     {
     	assert(dummy == null); // line 24
         assert(dummy.fun == 42); //line 25
     }
}

I thought, if I don't initialize a pointer, like the one in line 
21 (I assert this by the check in line 24) I can't use it line 
line 25.
However, I can...


More information about the Digitalmars-d-learn mailing list