www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11355] New: Copy through alias this with disabled this(this)

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 puremagic.com
        ReportedBy: m-ou.se m-ou.se


--- Comment #0 from Maurice Bos <m-ou.se 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: -------
Oct 25 2013