static immutable that has no initialiser - should this raise an error?

Cecil Ward cecil at cecilward.com
Tue May 30 04:11:00 UTC 2023


static immutable T foo;

T bar() {
     return foo;
     }

Should we get an error from the D compiler here as the 
initialiser has been forgotten? What do you think ?

I realise that foo is initialised to a defined value according to 
the type T, and this does seem to be the case here because foo is 
placed in readonly data (in the code segment on my x86-64 
machine) but it doesn’t seem like plausible code as foo can’t 
really be used for anything useful. Built this with GDC and 
inspected the generated asm.


More information about the Digitalmars-d-learn mailing list