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: [email protected]
Reporter: [email protected]
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
[email protected](10): Assertion failure
--