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
Changed issue name a little.
Comment #2 by k.hara.pg — 2013-05-14T20:18:51Z
Comment #3 by clugdbug — 2013-05-15T03:59:13Z
> Changed issue name a little. :) Your name change was exactly as grammatically incorrect as the original!
Comment #4 by github-bugzilla — 2013-06-25T14:39:43Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8231f4c9247aefa32e55a1e61f7533079cd147a1 fix Issue 10079 - Builit-in generated opAssign should be pure nothrow @safe on default https://github.com/D-Programming-Language/dmd/commit/9fad79d33406c82cbdec62ac3e6e5ad2e29db4e4 Merge pull request #2036 from 9rnsr/fix10079 Issue 10079 - Builit-in generated opAssign should be pure nothrow @safe on default
Comment #5 by k.hara.pg — 2014-09-18T10:50:26Z
*** Issue 9246 has been marked as a duplicate of this issue. ***