Bug 10079 – Built-in generated opAssign should be pure nothrow @safe by default
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-13T20:49:00Z
Last change time
2014-09-18T10:50:26Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2013-05-13T20:49:44Z
If a struct has postblit or destructor, assignment is automatically implemented with swap-and -destroy..
struct S {
this(this) {} // or ~this()
}
void main() {
S s1, s2;
s1 = s2; // is equivalent to
// auto tmp = s2 // bitwise copy
// swap(s1, tmp); // bitwise swap
// destroy tmp; // destroy old state of s1
}
The bitwise copy and swap are pure, nothrow and @safe. But currently this code doesn't work.
struct S {
this(this) pure nothrow @safe {}
// and/or ~this() pure nothrow @safe {}
}
void main() pure nothrow @safe {
S s1, s2;
s1 = s2;
}
test.d(7): Error: pure function 'D main' cannot call impure function 'test.S.opAssign'
test.d(7): Error: safe function 'D main' cannot call system function 'test.S.opAssign'
test.d(7): Error: s1.opAssign is not nothrow
test.d(5): Error: function D main 'main' is nothrow yet may throw
Comment #1 by bearophile_hugs — 2013-05-14T02:36:47Z