[Joke] C++ and D namings
Steven Schveighoffer
schveiguy at gmail.com
Wed Jan 20 16:07:26 UTC 2021
On 1/20/21 10:31 AM, Paul Backus wrote:
> 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.
>>
>
> 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].
>
Thanks for that link, I wasn't aware of that list.
In my Dconf online presentation, I found numerous bugs surrounding
unions and @safe code.
For instance, a union between a pointer and a scalar is considered
"safe" to access the scalar (even writing it!)
-Steve
More information about the Digitalmars-d
mailing list