Skip to content

Commit c8f2496

Browse files
committed
[clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854)
Resolves #95854 -- As per https://eel.is/c++draft/dcl.init#general-8.3
1 parent 1430405 commit c8f2496

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/include/clang/AST/DeclCXX.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,8 @@ class CXXRecordDecl : public RecordDecl {
13921392
bool allowConstDefaultInit() const {
13931393
return !data().HasUninitializedFields ||
13941394
!(data().HasDefaultedDefaultConstructor ||
1395-
needsImplicitDefaultConstructor());
1395+
needsImplicitDefaultConstructor()) ||
1396+
hasInClassInitializer();
13961397
}
13971398

13981399
/// Determine whether this class has a destructor which has no

clang/test/Sema/debug-95854.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
2+
//
3+
// expected-no-diagnostics
4+
5+
struct A {
6+
union {
7+
int n = 0;
8+
int m;
9+
};
10+
};
11+
const A a;

0 commit comments

Comments
 (0)