[Issue 22118] New: Const union causes false multiple-initialization error in constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 12 01:08:47 UTC 2021


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

          Issue ID: 22118
           Summary: Const union causes false multiple-initialization error
                    in constructor
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.097.0, the following program fails to compile:

---
struct NeedsInit
{
    int n;
    @disable this();
}

union U
{
    NeedsInit a;
}

struct S
{
    U u;
    this(const NeedsInit arg) const { u.a = arg; }
}
---

Compiler output, from run.dlang.io (with -vcolumns):

---
onlineapp.d(15,39): Error: const field `u` initialized multiple times
onlineapp.d(15,39):        Previous initialization is here.
---

The error message is false: there is only a single initialization of `u`.

Related: issue 21229.

--


More information about the Digitalmars-d-bugs mailing list