https://issues.dlang.org/show_bug.cgi?id=21225
Issue ID: 21225
Summary: preview=dtorfields inserts unnecessary dtor call in
nothrow ctors
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
The following code fails to compile with `-preview=dtorfields`:
======================================
struct Nothrow
{
~this() {}
}
struct NothrowConstructor
{
Nothrow member;
this(int) pure nothrow {}
}
======================================
Error: `pure` constructor `NothrowConstructor.this` cannot call impure
destructor `NothrowConstructor.~this`
The code currently fails to compile because the compiler rewrites the
user-defined constructor as:
try
<Old constructor>
catch (Exception e)
{
<Destructor>
throw e;
}
This causes the attribute missmatch (NothrowConstructor.~this not pure) albeit
the catch block is unreachable (unless the old constructor violates it's
`nothrow guarantee - which is UB anyway)
--