SafeD doesn't prevent me from dereferencing a null reference

Yutori yutori at fedora.email
Thu Aug 18 14:23:40 UTC 2022


```d
void main(immutable string[] argv) @safe @live {
         class Test {
                 string a;
         }
         auto testInstance = new Test;
         testInstance.a = "Test String";
         import std.stdio;
         testInstance.a.writeln;
         testInstance = null;
         testInstance.a.writeln;
}
/* Terminal output:
         Test String
         Segmentation fault
*/
```
Of course, this code must spit out a segmentation fault, as 
dereferencing null is illegal. However, the problem is, that it 
lets me compile the program in @safe.
I'm not entirely sure about what testInstance is defined as, but 
I assume it's a reference. I don't think dereferencing null 
should be allowed in SafeD. Or is this a design decision of D?


More information about the Digitalmars-d mailing list