@@ -2253,6 +2253,10 @@ bool InitListChecker::CheckFlexibleArrayInit(const InitializedEntity &Entity,
2253
2253
return FlexArrayDiag != diag::ext_flexible_array_init;
2254
2254
}
2255
2255
2256
+ static bool isInitializedStructuredList (const InitListExpr *StructuredList) {
2257
+ return StructuredList && StructuredList->getNumInits () == 1U ;
2258
+ }
2259
+
2256
2260
void InitListChecker::CheckStructUnionTypes (
2257
2261
const InitializedEntity &Entity, InitListExpr *IList, QualType DeclType,
2258
2262
CXXRecordDecl::base_class_const_range Bases, RecordDecl::field_iterator Field,
@@ -2499,8 +2503,7 @@ void InitListChecker::CheckStructUnionTypes(
2499
2503
StructuredList, StructuredIndex);
2500
2504
InitializedSomething = true ;
2501
2505
InitializedFields.insert (*Field);
2502
-
2503
- if (RD->isUnion () && StructuredList) {
2506
+ if (RD->isUnion () && isInitializedStructuredList (StructuredList)) {
2504
2507
// Initialize the first field within the union.
2505
2508
StructuredList->setInitializedFieldInUnion (*Field);
2506
2509
}
@@ -2585,7 +2588,7 @@ void InitListChecker::CheckStructUnionTypes(
2585
2588
CheckImplicitInitList (MemberEntity, IList, Field->getType (), Index,
2586
2589
StructuredList, StructuredIndex);
2587
2590
2588
- if (RD->isUnion () && StructuredList) {
2591
+ if (RD->isUnion () && isInitializedStructuredList ( StructuredList) ) {
2589
2592
// Initialize the first field within the union.
2590
2593
StructuredList->setInitializedFieldInUnion (*Field);
2591
2594
}
0 commit comments