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


--- Comment #0 from Don <clugdbug yahoo.com.au> 2010-06-17 00:03:49 PDT ---
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


--- Comment #1 from Richard Webb <webby beardmouse.org.uk> 2010-06-17 02:08:52
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


--- Comment #2 from Austin Hastings <ah08010-d yahoo.com> 2010-10-23 23:58:39
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


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2011-06-21 06:19:56 PDT ---
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



--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2011-06-21 06:34:18 PDT ---
*** 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



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2011-10-09 04:18:14 PDT ---
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


--- Comment #6 from Andrei Alexandrescu <andrei 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: -------
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


--- Comment #7 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2012-11-03
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