www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19317] New: dip1008 doesn't call the throwable's destructor


          Issue ID: 19317
           Summary: dip1008 doesn't call the throwable's destructor in
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: atila.neves gmail.com

The last assertion in the code below fails. This makes 1008 far less useful
than it could be. Exceptions have error messages, and the only way to construct
a useful message with runtime information is to allocate. Given that the
purpose of dip1008 is to avoid the GC and still be able to use exceptions, the
non error-prone way of doing this is to use an RAII string class.

However, that means that _d_delThrowable should call the class's destructor,
which it doesn't right now, resulting in a either a leak or the programmer
having to manually dispose of the memory.

class MyException: Exception {
    static int numInstances;
    this(string msg) {

    ~this() {

void main() {
    assert(MyException.numInstances == 0);

        throw new MyException("oops");
    catch(MyException _)
        assert(MyException.numInstances == 1);

    assert(MyException.numInstances == 0);

% dmd -dip1008 -run exception.d
core.exception.AssertError exception.d(21): Assertion failure

Oct 19 2018