[Joke] C++ and D namings

Paul Backus snarwin at gmail.com
Wed Jan 20 15:31:30 UTC 2021


On Wednesday, 20 January 2021 at 15:17:09 UTC, Steven 
Schveighoffer wrote:
> On 1/20/21 10:13 AM, Paul Backus wrote:
>> 
>> 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);
>> }
>
> That seems like a bug. Writing the x directly fails in @safe 
> code.
>
> -Steve

I agree. Though now that I take a look at the spec, it seems like 
the bug may actually be in the line

     writeln(a.y);

...since accessing immutable data that's overlapped with mutable 
data breaks safe aliasing [1].

[1] https://dlang.org/spec/function.html#safe-aliasing


More information about the Digitalmars-d mailing list