Skip to content

Clang incorrectly rejects default construction of union with nontrivial member #48416

Closed
@miscco

Description

@miscco
Bugzilla Link 49072
Version trunk
OS Windows NT
CC @CaseyCarter,@zygoloid

Extended Description

Consider the following valid TU:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions