[Issue 10079] New: Builit-in generated opAssign should be pure nothrow @safe in default
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 13 20:49:46 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10079
Summary: Builit-in generated opAssign should be pure nothrow
@safe in default
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: rejects-valid
Severity: major
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: k.hara.pg at gmail.com
--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2013-05-13 20:49:44 PDT ---
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
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list