www.digitalmars.com         C & C++   DMDScript  

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


          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


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 2020