Bug 11355 – Copy through alias this with @disabled this(this)

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-25T12:19:00Z
Last change time
2015-02-18T03:38:12Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
m-ou.se

Comments

Comment #0 by m-ou.se — 2013-10-25T12:19:35Z
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.
Comment #1 by nick — 2014-07-08T14:40:11Z
I think the move line should be disallowed: A a = move(b); // implicit copy, currently allowed A a = move(b).a; // currently disallowed by @disable this(this) (The second line is equivalent, just expanding via alias this). I think this test case may be the same bug: struct A { @disable this(this); // Prevent copying } struct B { A a; alias a this; } void main() { A a = B(); // implicit copy of temporaryB.a should be disallowed }
Comment #2 by k.hara.pg — 2014-10-08T14:02:14Z
Comment #3 by github-bugzilla — 2014-10-08T17:09:05Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1730307642768e53d84aadea6352e8dd4f7eb949 fix Issue 11355 - Copy through alias this with @disabled this(this) https://github.com/D-Programming-Language/dmd/commit/d2ab695c18ad1002bbdf61dedecee71cf0742252 Merge pull request #4054 from 9rnsr/fix11355 Issue 11355 - Copy through alias this with @disabled this(this)
Comment #4 by github-bugzilla — 2015-02-18T03:38:12Z