File tree 3 files changed +61
-1
lines changed 3 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -539,6 +539,9 @@ Bug Fixes to C++ Support
539
539
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
540
540
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
541
541
- Fix a crash when recovering an invalid expression involving an explicit object member conversion operator. (#GH112559)
542
+ - Clang incorrectly considered a class with an anonymous union member to not be
543
+ const-default-constructible even if a union member has a default member initializer.
544
+ (#GH95854).
542
545
543
546
Bug Fixes to AST Handling
544
547
^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -1060,6 +1060,9 @@ void CXXRecordDecl::addedMember(Decl *D) {
1060
1060
if (isUnion () && !Field->isAnonymousStructOrUnion ())
1061
1061
data ().HasVariantMembers = true ;
1062
1062
1063
+ if (isUnion () && IsFirstField)
1064
+ data ().HasUninitializedFields = true ;
1065
+
1063
1066
// C++0x [class]p9:
1064
1067
// A POD struct is a class that is both a trivial class and a
1065
1068
// standard-layout class, and has no non-static data members of type
@@ -1128,7 +1131,10 @@ void CXXRecordDecl::addedMember(Decl *D) {
1128
1131
data ().DefaultedCopyConstructorIsDeleted = true ;
1129
1132
}
1130
1133
1131
- if (!Field->hasInClassInitializer () && !Field->isMutable ()) {
1134
+ if (isUnion () && !Field->isMutable ()) {
1135
+ if (Field->hasInClassInitializer ())
1136
+ data ().HasUninitializedFields = false ;
1137
+ } else if (!Field->hasInClassInitializer () && !Field->isMutable ()) {
1132
1138
if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl ()) {
1133
1139
if (FieldType->hasDefinition () && !FieldType->allowConstDefaultInit ())
1134
1140
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}}
44
+
45
+ struct E {
46
+ union {
47
+ int n;
48
+ int m=0 ;
49
+ };
50
+ };
51
+ const E e;
You can’t perform that action at this time.
0 commit comments