[Issue 19065] New: Struct invariant violated in @safe with T.init

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 6 08:25:36 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19065

          Issue ID: 19065
           Summary: Struct invariant violated in @safe with T.init
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: default_357-line at yahoo.de

Consider this code:

struct S
{
    @disable this();
    bool b = false;
    this(int) { b = true; }
    invariant { assert(b == true); }
    @safe ~this() { }
}

@safe void main()
{
    S s = S.init;
}

I believe the appropriate response to this is that invariant checking must be
disabled on struct destructors. Struct destructors are supposed to be able to
handle T.init anyways; otherwise the behavior of moveEmplace is nonsensical.
This problem is, as far as I can tell, completely solved by requiring structs
to be either invariant-valid or T.init at destructor call.

--


More information about the Digitalmars-d-bugs mailing list