[Issue 4338] Structs with non-const destructors cannot be used as const parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 17 21:13:31 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=4338


Andrei Alexandrescu <andrei at metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei at metalanguage.com


--- Comment #6 from Andrei Alexandrescu <andrei at metalanguage.com> 2012-01-17 21:13:29 PST ---
With the current 2.058 from head the code compiles. But it shouldn't because
it's unsound.

Mutable destructors shouldn't apply to objects that were immutable, otherwise
they can mutate immutable objects. Consider:

struct A {
    int* p;
    ~this() { *p = 5; }
}

void main() {
    auto p = new immutable(int);
    { auto a = immutable(A)(p); }
    assert(*p == 0);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list