-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) #96301
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
Conversation
|
@llvm/pr-subscribers-clang Author: Rajveer Singh Bharadwaj (Rajveer100) ChangesResolves #95854 -- As per https://eel.is/c++draft/dcl.init#general-8.3 Full diff: https://github.com/llvm/llvm-project/pull/96301.diff 2 Files Affected:
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index fb52ac804849d..1d1083a5d6205 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1392,7 +1392,8 @@ class CXXRecordDecl : public RecordDecl {
bool allowConstDefaultInit() const {
return !data().HasUninitializedFields ||
!(data().HasDefaultedDefaultConstructor ||
- needsImplicitDefaultConstructor());
+ needsImplicitDefaultConstructor()) ||
+ hasInClassInitializer();
}
/// Determine whether this class has a destructor which has no
diff --git a/clang/test/Sema/debug-95854.cpp b/clang/test/Sema/debug-95854.cpp
new file mode 100644
index 0000000000000..1fb976558650d
--- /dev/null
+++ b/clang/test/Sema/debug-95854.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+//
+// expected-no-diagnostics
+
+struct A {
+ union {
+ int n = 0;
+ int m;
+ };
+};
+const A a;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this fix. It needs a release note and your summary should have some more details on what the cause of the bug is and how your PR fixes it. efriedma-quic's comment provides a good framework for explaining the cause.
It also looks like your change broke some tests:
Clang :: AST/Interp/records.cpp
Clang :: SemaCXX/cxx0x-cursory-default-delete.cppAre these expected breaks? If so then please update these tests
c8f2496 to
b964923
Compare
3fb29e5 to
751e630
Compare
|
@zygoloid |
1a25f02 to
7efe2bd
Compare
|
@zygoloid |
Sirraide
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the changes generally make sense.
7efe2bd to
03c02ea
Compare
49e6fb5 to
3ccb1c9
Compare
|
@Sirraide The tests pass, not sure about the failure though. |
shafik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the test failures look related to the changes can you push and empty change to see if rerunning the tests comes up clean?
3ccb1c9 to
8796f60
Compare
|
Only windows failed. PS: Pushed again to resolve merge conflict. |
8796f60 to
387e838
Compare
cor3ntin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are more tests to consider https://godbolt.org/z/M6fj5zTfq
Thanks!
387e838 to
dfc4445
Compare
|
@cor3ntin |
|
Neither GCC, EDG nor MSVC agree with us https://godbolt.org/z/Wqrhnz63a |
dfc4445 to
f42cea2
Compare
d6b3358 to
1e1e446
Compare
|
@shafik |
cor3ntin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks!
Give a couple of days to @shafik before merging
|
Thanks for the approval @cor3ntin, could you land this for me?! |
1e1e446 to
38ded4c
Compare
38ded4c to
c12be47
Compare
…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
c12be47 to
cbd6e83
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/7389 Here is the relevant piece of the build log for the reference |
Resolves #95854
-- As per https://eel.is/c++draft/dcl.init#general-8.3