www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15044] New: [Reg 2.068.0] destroy might leak memory


          Issue ID: 15044
           Summary: [Reg 2.068.0] destroy might leak memory
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: code dawg.eu

cat > bug.d << CODE
struct Vector

    RefCounted!Vector dup()
        return RefCounted!Vector(&this);

struct RefCounted(T)
        .destroy(*t); // __xdtor of Vector not yet available
        static assert(__traits(hasMember, T, "__xdtor"));
    T* t;

dmd -c bug
bug.d(18): Error: static assert  (__traits(hasMember, Vector, "__xdtor")) is
bug.d(7):        instantiated from here: RefCounted!(Vector)

The problem is that __xdtor is not yet available when the destructor of
RefCounted is analyzed, hence .destroy won't call the destructor of Vector.
It seems that the creation of __xdtor should happen earlier.

Sep 11 2015