[Issue 20880] New: [DIP1000] Temporaries escape innards absent destructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 29 21:09:07 UTC 2020


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 at puremagic.com
          Reporter: stanislav.blinov at 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();
}

--


More information about the Digitalmars-d-bugs mailing list