D defined behavior

Arine arine1283798123 at gmail.com
Mon Apr 27 18:21:45 UTC 2020


On Monday, 27 April 2020 at 15:14:06 UTC, Luís Marques wrote:
> On Monday, 27 April 2020 at 14:57:09 UTC, Johan wrote:
>> Yes, D has UB.
>
> Could you expand on that, please? Do you mean in the 
> implementation or per the spec? Outside @safe or also in @safe 
> code? Etc.

D has UB even in @safe. @safe doesn't mean there's no UB, it 
simply means it is memory safe. This will print both true and 
false:


import std.stdio;

@safe void foo() {

     bool v = void;

     if ( v ) {
         writeln("true");
     }

     if ( !v ) {
         writeln("false");
     }

}

@safe void main() {
     foo();
}


More information about the Digitalmars-d mailing list