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)
@MoonlightSentinel created dlang/dmd pull request #11692 "Fix 21225 - preview=dtorfields inserts unnecessary dtor calls..." fixing this issue: - Fix 21225 - preview=dtorfields inserts unnecessary dtor calls... ... in nothrow ctors Fixed by not inserting the destructor call if the constructor is `nothrow` - which makes the generated `catch`-block unreachable (unless the ctor violates it's `nothrow` guarantee - which is UB). This also saves time & memory spent on generating unused AST elements. https://github.com/dlang/dmd/pull/11692
dlang/dmd pull request #11692 "Fix 21225 - preview=dtorfields inserts unnecessary dtor calls..." was merged into master: - 15caafef20af92469b11cfaaeaf16b4e28e2b1d3 by MoonlightSentinel: Fix 21225 - preview=dtorfields inserts unnecessary dtor calls... ... in nothrow ctors Fixed by not inserting the destructor call if the constructor is `nothrow` - which makes the generated `catch`-block unreachable (unless the ctor violates it's `nothrow` guarantee - which is UB). This also saves time & memory spent on generating unused AST elements. https://github.com/dlang/dmd/pull/11692