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

Dom DiSc dominikus at scherkl.de
Wed May 31 09:30:56 UTC 2023


On Tuesday, 30 May 2023 at 04:11:00 UTC, Cecil Ward wrote:
> 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 ?
No.
There are no un-initialized values in D.
It gets its default value, if no explicit value is given.
That's intended, not an error.
If you need an un-initialized value, set it =void.
Of course, for immutable values that makes no sense at all.
But I think, this already gives you an error.



More information about the Digitalmars-d-learn mailing list