[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 21 06:02:31 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Rajveer Singh Bharadwaj (Rajveer100)
<details>
<summary>Changes</summary>
Resolves #<!-- -->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:
- (modified) clang/include/clang/AST/DeclCXX.h (+2-1)
- (added) clang/test/Sema/debug-95854.cpp (+11)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/96301
More information about the cfe-commits
mailing list