[Issue 22143] New: Throwable ctor doesn't increment chained exception's ref count

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 25 19:58:37 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22143

          Issue ID: 22143
           Summary: Throwable ctor doesn't increment chained exception's
                    ref count
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: rmanth at gmail.com

If you catch a dip1008 ref-counted throwable and pass it into the constructor
of an `Error` or `Exception` the ref count isn't incremented. You have to
assign via the `next` property to achieve this.

-----------------------------------
module chain

void main()
{
    try {
        throw new Exception("reasons...");
    } catch(Exception e1) {
        auto rc1 = e1.refcount();
        auto e2 = new Exception("stuff...", e1); // should increment ref count
        assert(e1.refcount() == rc1+1); // Assertion failure
    }
}
------------------------------------

dmd -preview=dip1008 -run chain.d
core.exception.AssertError at chain.d(10): Assertion failure

--


More information about the Digitalmars-d-bugs mailing list