www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4338] New: Structs with non-const destructors cannot be used as const parameters

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4338

           Summary: Structs with non-const destructors cannot be used as
                    const parameters
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au



TEST CASE:
struct A {
    ~this() {}
}

void foo(const A a) {}
---------
bug.d(4): Error: destructor bug.A.~this () is not callable using argument types
()

Workaround is to change ~this() into const ~this().

I find this whole situation pretty weird.  How can a destructor be const? (Is a
const struct effectively 'tail const', so that a const destructor only destroys
the non-const bit?) 
And anyway, should a destructor be called on non-mutable function parameters?
In any case, the error message is rather poor.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4338


Richard Webb <webby beardmouse.org.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |webby beardmouse.org.uk



PDT ---
Same as http://d.puremagic.com/issues/show_bug.cgi?id=3606 ?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4338


Austin Hastings <ah08010-d yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ah08010-d yahoo.com



PDT ---
I stumbled into this problem with a struct having an immutable member.

Apparently, any kind of const-ness taints the struct, which prevents calling
the destructor. 

In my case, declaring the destructor const/immutable didn't help. :(
Apparently, you can't have struct with immutable members as an "in" parameter,
since that does the "const scope" thing, which triggers the destructor, which
causes the failure.


Also: the "const ~this()" syntax works, but "~this() const" does not, which
seems odd since it works for other method names.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 23 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4338


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg gmail.com



Now this issue is temporary fixed by calling mutable dtor from const object.

See change of declaration.c and Walter's comment.
https://github.com/D-Programming-Language/dmd/commit/aef37eb0c8986a508ccf185286465b4cbef8a066#L1R1721

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 21 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4338




*** Issue 3606 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 21 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4338




Postblit has similar problem, see bug 4867.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4338


Andrei Alexandrescu <andrei metalanguage.com> changed:

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



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: -------
Jan 17 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4338


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com



16:51:43 MSK ---
Consolidated into Issue 8956.

Do not close this issue as a duplicate because it is another issue. E.g. it can
be closed as WONTFIX if destructors will become qualifier-overloadable.

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