[Issue 21198] New: Inout copy constructor on union field does not prevent copy-initialization of union

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 25 16:26:35 UTC 2020


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

          Issue ID: 21198
           Summary: Inout copy constructor on union field does not prevent
                    copy-initialization of union
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

Example program:

---
struct S
{
    this(ref inout(S) other) inout {}
}

union U
{
    S s;
}

static assert(!__traits(compiles,
    (U original) { U copy = original; }
));
---

The language spec says:

> If a union S has fields that define a copy constructor, whenever an object of
> type S is initialized by copy, an error will be issued. The same rule applies
> to overlapped fields (anonymous unions).

According to this paragraph, the static assert above should pass. However, as
of DMD 2.093.1, it fails.

--


More information about the Digitalmars-d-bugs mailing list