www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20880] New: [DIP1000] Temporaries escape innards absent

https://issues.dlang.org/show_bug.cgi?id=20880

          Issue ID: 20880
           Summary: [DIP1000] Temporaries escape innards absent destructor
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: stanislav.blinov gmail.com

This behavior is, at the very least, inconsistent. Furthermore, with dtor
uncommented, resulting error message for the second test is somewhat cryptic.

// dmd -dip1000

 safe:

struct S {
    private int* ptr;
    // Uncomment following line to make both tests fail to compile
    //~this() {}

    int* get() return { return ptr; }
}

// With dtor commented, this fails to compile (as expected)
unittest {
    S s;
    // NOTE: lambda is unnecessary, it is here solely
    // to document expected behavior of the second test
    int* outlive = {
        S temporary;
        return temporary.get();
    } ();
}

// With dtor commented, this compiles
unittest {
    int* outlive = S().get();
}

--
May 29