mutable destructor? WAT???

Dicebot via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 28 03:35:49 PDT 2016


Looks correct to me. This const annotation does not prevent you 
from deleting memory or free'ing external resources - but it does 
ensure no transitive mutations for data reachable from struct 
fields. If it allowed destroying with mutable destructor, type 
system hole like this would be legal:

struct S
{
     char[] str;
     ~this() { str[0] = 'a'; }
}

auto s = new const S("abcd");
destroy(s); // mutates immutable literal


More information about the Digitalmars-d-learn mailing list