www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15648] New: Destructor constness doesn't take member


          Issue ID: 15648
           Summary: Destructor constness doesn't take member destructor
                    attributes into account
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: Marco.Leise gmx.de

I'm unable to implement an  nogc hash table that has immutable keys that have
dtors and contain members with dtors. Here is the reduced version of such a

    struct HashTable
        immutable(Key)* keys;

            destroy( keys[0] );

    struct Key
        KeyData data;
        ~this() const {}

    struct KeyData
        ~this() const {}

The compiler will complain:
  Error: mutable method main.Key.~this is not callable using a immutable object
  Error: template instance object._destructRecurse!(immutable(Key)) error

This seems to come from calling an aggregated non-const destructor and I don't
know of a feasible workaround. The ones I know of are:
 1) remove immutability from keys and const from dtors
 2) merge KeyData's dtor into that of Key (but Key is a generic templated
wrapper struct)

Feb 05 2016