Bug 21225 – preview=dtorfields inserts unnecessary dtor call in nothrow ctors

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-09-04T23:46:02Z
Last change time
2020-09-05T19:04:09Z
Keywords
pull
Assigned to
No Owner
Creator
moonlightsentinel

Comments

Comment #0 by moonlightsentinel — 2020-09-04T23:46:02Z
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)
Comment #1 by dlang-bot — 2020-09-04T23:50:07Z
@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
Comment #2 by dlang-bot — 2020-09-05T19:04:09Z
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