[Issue 11355] New: Copy through alias this with @disabled this(this)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Oct 25 12:19:36 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11355
Summary: Copy through alias this with @disabled this(this)
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: major
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: m-ou.se at m-ou.se
--- Comment #0 from Maurice Bos <m-ou.se at m-ou.se> 2013-10-25 12:19:35 PDT ---
I'm trying to use a struct for RAII (like C++'s unique_ptr), so i
@disabled this(this). However, it's still getting copied somehow:
struct A {
int some_resource = 0;
~this() { if (some_resource) writeln("Freeing resource."); }
@disable this(this); // Prevent copying
}
struct B {
A a;
alias a this;
}
void main() {
B b;
b.some_resource = 100;
A a = move(b);
}
The above code prints 'Freeing resource.' twice!
See it in action on http://dpaste.dzfl.pl/6461df03
I guess the first one is from the temporary B that move(b) gives.
However, that temporary should be moved into a and then left in
B.init state, but that doesn't happen.
--
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