[Issue 15648] Destructor constness doesn't take member destructor attributes into account

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jul 2 08:33:31 PDT 2017


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

Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dlang-bugzilla at thecybershad
                   |                            |ow.net
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
I believe the operation destroy(x) where x is an immutable value type was never
supported, as part of destroy's operation is to clobber the value of x with its
.init value - see object.d, the `void destroy(T)(ref T obj) if (is(T ==
struct))` overload. 

Changing the destroy() call with an explicit invocation of the inclusive
destructor (`keys[0].__xdtor();`) does seem to illustrate the problem better, I
think - the inclusive destructor should have its constness inferred from the
destructors it calls:

$ cat test.d 
struct HashTable
{
    immutable(Key)* keys;

    ~this()
    {
        keys[0].__xdtor();
    }
}

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

struct KeyData
{
    ~this() const {}
}

$ dmd -o- test.d
test.d(7): Error: mutable method test.Key.~this is not callable using a
immutable object

--


More information about the Digitalmars-d-bugs mailing list