Bug 19908 – [DIP1000] union with single member should not generate cannot access pointers in `@safe` code that overlap other fields error

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-05-28T14:15:28Z
Last change time
2020-03-13T04:03:48Z
Assigned to
No Owner
Creator
Nicholas Wilson

Comments

Comment #0 by iamthewilsonator — 2019-05-28T14:15:28Z
Unions with a single element (such as where they are used purely to suppress calling constructors and destructors) should not generate errors related to accessing overlapped pointers in @safe code since no overlapped access can occur. struct Nullable(T) { private bool _isNull = true; private union DontCallDestructorT { T payload; } private DontCallDestructorT _value = DontCallDestructorT.init; @property ref inout(T) get() inout @safe pure nothrow { { enum message = "Called `get' on null Nullable!" ~ T.stringof ~ "."; assert(!isNull, message); return _value.payload; // <<< } } std/typecons.d(2972): Error: field `DontCallDestructorT.payload` cannot access pointers in `@safe` code that overlap other fields uncovered by https://github.com/dlang/dmd/pull/9909
Comment #1 by bugzilla — 2020-03-12T09:38:36Z
The example does not compile due to mismatched { }. Remove the extra { and it compiles without error. Furthermore, the error message references std.typecons, but no imports are done by the example. Needs a reproducible example.
Comment #2 by pro.mathias.lang — 2020-03-13T04:03:48Z
Looking at the linked PR, the error only shows up because the DMD PR was not adequate. Closing as invalid.