Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
miscco opened this issue Feb 6, 2021 · 2 comments
Closed
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@miscco
Copy link
Contributor

miscco commented Feb 6, 2021

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.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@shafik
Copy link
Collaborator

shafik commented Mar 14, 2023

Notes are non-normative, so you want to refer to class.default.ctor to back up this assertion.

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Mar 14, 2023
@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2023

@llvm/issue-subscribers-clang-frontend

CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Mar 17, 2023
… unions

If a union has explicit initializers for some members, we shouldn't delete
its default constructor.
Fixes llvm/llvm-project#48416.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D145851
agozillon pushed a commit to ROCm-Developer-Tools/llvm-project that referenced this issue Mar 17, 2023
… unions

If a union has explicit initializers for some members, we shouldn't delete
its default constructor.
Fixes llvm/llvm-project#48416.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D145851
a2flo pushed a commit to a2flo/floor_llvm that referenced this issue Feb 2, 2025
[Clang][Sema] Fix incorrect deletion of default constructors for some unions

If a union has explicit initializers for some members, we shouldn't delete
its default constructor.
Fixes llvm#48416.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D145851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
Status: Done
Development

No branches or pull requests

4 participants