[Issue 21223] New: nothrow constructor may call throwing constructor with

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 4 07:53:08 UTC 2020


          Issue ID: 21223
           Summary: nothrow constructor may call throwing constructor with
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: moonlightsentinel at disroot.org

Consider the following example:

struct HasDtor
        // Enforce @system, ... just to be sure
        __gshared int i;
        if (++i)
            throw new Exception(new immutable(char)[](10));

// The user-defined dtor matches the ctor attributes
struct Strict
    HasDtor member;

    this(int) pure nothrow @nogc @safe {}

    ~this() pure nothrow @nogc @safe {}


Compiling this code with `-preview=dtorfields` will insert a potential call to
HasDtor.~this into Strict.this. This is obviously an error because the
destructor doesn't match the attributes enforced by the constructor, yet only
pure nothrow @nogc will be reported while non-nothrow is accepted.


More information about the Digitalmars-d-bugs mailing list