www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21225] New: preview=dtorfields inserts unnecessary dtor call

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: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

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)

--
Sep 04 2020