-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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 considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer #95854
Comments
@llvm/issue-subscribers-clang-frontend Author: Richard Smith (zygoloid)
Testcase:
```c++
struct A {
union {
int n = 0;
int m;
};
};
const A a;
```
This is valid, but Clang rejects:
```console
<source>:7:9: error: default initialization of an object of const type 'const A' without a user-provided default constructor
```
(Clang accepts if `m` is removed.) See https://eel.is/c++draft/dcl.init#general-8.3 -- because `n` has an initializer, the entire anonymous union is treated as initialized.
|
@llvm/issue-subscribers-c-11 Author: Richard Smith (zygoloid)
Testcase:
```c++
struct A {
union {
int n = 0;
int m;
};
};
const A a;
```
This is valid, but Clang rejects:
```console
<source>:7:9: error: default initialization of an object of const type 'const A' without a user-provided default constructor
```
(Clang accepts if `m` is removed.) See https://eel.is/c++draft/dcl.init#general-8.3 -- because `n` has an initializer, the entire anonymous union is treated as initialized.
|
I think CXXRecordDecl::allowConstDefaultInit() needs to special-case unions to handle the rule (specifically, it needs to check for HasInClassInitializer). |
Hi! This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below. |
@llvm/issue-subscribers-good-first-issue Author: Richard Smith (zygoloid)
Testcase:
```c++
struct A {
union {
int n = 0;
int m;
};
};
const A a;
```
This is valid, but Clang rejects:
```console
<source>:7:9: error: default initialization of an object of const type 'const A' without a user-provided default constructor
```
(Clang accepts if `m` is removed.) See https://eel.is/c++draft/dcl.init#general-8.3 -- because `n` has an initializer, the entire anonymous union is treated as initialized.
|
This is my first time contributing to this project. I would like to give it a try. Could you assign it to me? |
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. This is valid as per ``8.3`` in `Draft C++ Standard <https://eel.is/c++draft/dcl.init#general-8.3>`_. The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs special-case unions to handle the rule. (#GH95854). ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
Hi @zygoloid and @efriedma-quic, |
We put that label on issues when we think it's something that a new contributor might be able to tackle as a way to get introduced to the code base.
Any contributor can tackle any issue they'd like; we don't typically use issue assignments because of how easy it is for the assignment to go stale and then nobody works on it (but we have started assigning people when they ask to be assigned, sort of as a soft trial to see how well it goes). FWIW, @Rajveer100 is also a relative newcomer to the community and they may not have noticed that this issue was already assigned to you. |
Hi @AaronBallman |
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. This is valid as per ``8.3`` in `Draft C++ Standard <https://eel.is/c++draft/dcl.init#general-8.3>`_. The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs special-case unions to handle the rule. (#GH95854). ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. This is valid as per ``8.3`` in `Draft C++ Standard <https://eel.is/c++draft/dcl.init#general-8.3>`_. The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs special-case unions to handle the rule. (#GH95854). ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) Resolves llvm#95854 Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer. ``` struct A { union { int n = 0; int m; }; }; const A a; ``` -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (#95854) (#96301) Resolves #95854 -- As per https://eel.is/c++draft/dcl.init#general-8.3
…onstructible even if a union member has a default member initializer (llvm#95854) (llvm#96301) Resolves llvm#95854 -- As per https://eel.is/c++draft/dcl.init#general-8.3
Testcase:
This is valid, but Clang rejects:
<source>:7:9: error: default initialization of an object of const type 'const A' without a user-provided default constructor
(Clang accepts if
m
is removed.) See https://eel.is/c++draft/dcl.init#general-8.3 -- becausen
has an initializer, the entire anonymous union is treated as initialized.The text was updated successfully, but these errors were encountered: