[Joke] C++ and D namings

Paul Backus snarwin at gmail.com
Wed Jan 20 15:13:49 UTC 2021


On Wednesday, 20 January 2021 at 14:33:11 UTC, Steven 
Schveighoffer wrote:
> Your immutable case would ALWAYS be UB, but only if you 
> accessed the member you didn't set.
>
> And again, disallowed in @safe code.

This version compiles even with @safe:

import std.stdio;
union t {int x; immutable int y;};
void main() @safe
{

     t a = { x: 0 };
     writeln(a.y);
     t b = { y: 4 };
     a = b; // oops
     writeln(a.y);
}


More information about the Digitalmars-d mailing list