Thread overview
[Issue 7349] assert(0) in class destructor - bad (or incorrect) error
May 20, 2014
joakim@airpost.net
May 20, 2014
safety0ff.bugz
May 20, 2014
Joakim
Nov 13, 2014
Walter Bright
Feb 20, 2016
Sobirari Muhomori
Jan 22, 2021
Walter Bright
Jan 22, 2021
Walter Bright
Jun 01, 2021
Mathias LANG
May 20, 2014
https://issues.dlang.org/show_bug.cgi?id=7349

--- Comment #1 from joakim@airpost.net ---
Is this a bug or is it not allowed to assert in a destructor?  I ran into this while running the druntime tests on Android/x86, was very annoying as the assert in core.sync.semaphore was swallowed up by the InvalidMemoryOperationError so I didn't know where it was actually coming from till I stuck printfs everywhere.  If the assert shouldn't be allowed, druntime and possibly other D code needs to be cleaned up to get rid of any asserts in destructors.

--
May 20, 2014
https://issues.dlang.org/show_bug.cgi?id=7349

safety0ff.bugz <safety0ff.bugz@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |safety0ff.bugz@gmail.com

--- Comment #2 from safety0ff.bugz <safety0ff.bugz@gmail.com> ---
The current GC does not support allocation during destruction (quality of
implementation issue.)
When the assert fails and tries to allocate it causes an invalid memory
operation error.

--
May 20, 2014
https://issues.dlang.org/show_bug.cgi?id=7349

--- Comment #3 from Joakim <joakim@airpost.net> ---
(In reply to safety0ff.bugz from comment #2)
> The current GC does not support allocation during destruction (quality of
> implementation issue.)
> When the assert fails and tries to allocate it causes an invalid memory
> operation error.

Yeah, I know what's happening, which I wrote about in github, the question is how the people who build D plan on resolving it.

It doesn't help when druntime itself is asserting in its destructors, if this hasn't worked in a long time.  Should we be taking all asserts out of destructors?

--
November 13, 2014
https://issues.dlang.org/show_bug.cgi?id=7349

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
The real problem is that assert(0) is attempting to allocate.

--
February 20, 2016
https://issues.dlang.org/show_bug.cgi?id=7349

Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matt.elkins@gmail.com

--- Comment #5 from Sobirari Muhomori <dfj1esp02@sneakemail.com> ---
*** Issue 15705 has been marked as a duplicate of this issue. ***

--
January 22, 2021
https://issues.dlang.org/show_bug.cgi?id=7349

--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> ---
The offending code:

https://github.com/dlang/druntime/blob/f94e816c1dd229cbb133085a6fc41d1bd6d45594/src/core/exception.d#L417-L449

Andrei suggests using a thread local static object to throw.

--
January 22, 2021
https://issues.dlang.org/show_bug.cgi?id=7349

--- Comment #7 from Walter Bright <bugzilla@digitalmars.com> ---
https://github.com/dlang/druntime/pull/1710

--
January 22, 2021
https://issues.dlang.org/show_bug.cgi?id=7349

thomas.bockman@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thomas.bockman@gmail.com

--- Comment #8 from thomas.bockman@gmail.com ---
Given that assert(0) is intended to crash the program, wouldn't it also be reasonable to just allocate using stdc's malloc, or an OS-specific syscall, and not worry about explicitly freeing the memory? It's just going to get freed by the OS when the process terminates an instant later, anyway...

--
June 01, 2021
https://issues.dlang.org/show_bug.cgi?id=7349

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |pro.mathias.lang@gmail.com
         Resolution|---                         |FIXED

--- Comment #9 from Mathias LANG <pro.mathias.lang@gmail.com> ---
Fixed in https://github.com/dlang/druntime/pull/3476

--