[llvm-bugs] [Bug 49072] New: Clang incorrectly rejects default construction of union with nontrivial member

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Feb 6 11:13:02 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49072

            Bug ID: 49072
           Summary: Clang incorrectly rejects default construction of
                    union with nontrivial member
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mschellenbergercosta at googlemail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Consider the following valid TU:

```cpp
struct TriviallyConstructible {};
struct BadNontrivialClass {
    BadNontrivialClass() {}
};

union U {
    TriviallyConstructible first{};
    BadNontrivialClass second;
};

U u;
```

Currently clang rejects this with:

```
<source>:11:3: error: call to implicitly-deleted default constructor of 'U'
U u;
  ^
<source>:8:24: note: default constructor of 'U' is implicitly deleted because
variant field 'second' has a non-trivial default constructor
    BadNontrivialClass second;
```

However, according to the standard
(https://eel.is/c++draft/class.union#general-4) the member initializer of
`first` makes this a valid construct.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210206/66f4bf42/attachment.html>


More information about the llvm-bugs mailing list