File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,9 @@ Bug Fixes to C++ Support
318318 of the current instantiation in all cases.
319319- Fix evaluation of the index of dependent pack indexing expressions/types specifiers (#GH105900)
320320- Correctly handle subexpressions of an immediate invocation in the presence of implicit casts. (#GH105558)
321+ - Clang incorrectly considered a class with an anonymous union member to not be
322+ const-default-constructible even if a union member has a default member initializer.
323+ (#GH95854).
321324
322325Bug Fixes to AST Handling
323326^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -1057,6 +1057,9 @@ void CXXRecordDecl::addedMember(Decl *D) {
10571057 if (isUnion () && !Field->isAnonymousStructOrUnion ())
10581058 data ().HasVariantMembers = true ;
10591059
1060+ if (isUnion () && IsFirstField)
1061+ data ().HasUninitializedFields = true ;
1062+
10601063 // C++0x [class]p9:
10611064 // A POD struct is a class that is both a trivial class and a
10621065 // standard-layout class, and has no non-static data members of type
@@ -1125,7 +1128,10 @@ void CXXRecordDecl::addedMember(Decl *D) {
11251128 data ().DefaultedCopyConstructorIsDeleted = true ;
11261129 }
11271130
1128- if (!Field->hasInClassInitializer () && !Field->isMutable ()) {
1131+ if (isUnion () && !Field->isMutable ()) {
1132+ if (Field->hasInClassInitializer ())
1133+ data ().HasUninitializedFields = false ;
1134+ } else if (!Field->hasInClassInitializer () && !Field->isMutable ()) {
11291135 if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl ()) {
11301136 if (FieldType->hasDefinition () && !FieldType->allowConstDefaultInit ())
11311137 data ().HasUninitializedFields = true ;
Original file line number Diff line number Diff line change 1+ // RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
2+
3+ struct A {
4+ union {
5+ int n = 0 ;
6+ int m;
7+ };
8+ };
9+ const A a;
10+
11+ struct B {
12+ union {
13+ struct {
14+ int n = 5 ;
15+ int m;
16+ };
17+ };
18+ };
19+ const B b; // expected-error {{default initialization of an object of const type 'const B' without a user-provided default constructor}}
20+
21+ struct S {
22+ int i;
23+ int j;
24+ };
25+
26+ struct T {
27+ T () = default ;
28+ };
29+
30+ struct C {
31+ union {
32+ S s;
33+ };
34+ };
35+
36+ struct D {
37+ union {
38+ T s;
39+ };
40+ };
41+
42+ const C c; // expected-error {{default initialization of an object of const type 'const C' without a user-provided default constructor}}
43+ const D d; // expected-error {{default initialization of an object of const type 'const D' without a user-provided default constructor}}
You can’t perform that action at this time.
0 commit comments