Bug 18592 – Associative array assignment with a destructor should be @safe if the destructor is @safe

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-11T20:27:47Z
Last change time
2018-03-15T03:16:58Z
Keywords
safe
Assigned to
No Owner
Creator
Seb
See also
https://issues.dlang.org/show_bug.cgi?id=18000

Comments

Comment #0 by greensunny12 — 2018-03-11T20:27:47Z
cat > main.d << EOF void main() @safe { struct ThrowingElement { int i; ~this() { assert(1); } } ThrowingElement[int] aa; aa[0] = ThrowingElement(0); } EOF The problem is that the generated opAssign is @system: ref return @system ThrowingElement opAssign(ThrowingElement p) { (ThrowingElement __swap2 = void;) , __swap2 = this , this = p , __swap2.~this(); return this; }
Comment #1 by bugzilla — 2018-03-13T06:05:20Z
The solution is likely the same as for https://github.com/dlang/dmd/pull/8011
Comment #2 by bugzilla — 2018-03-15T03:16:58Z
The example compiles successfully if ~this() is given the @safe attribute. @safe for the outer function is not transitively applied - perhaps it should be, but that isn't the way it works at the moment.