@@ -2253,6 +2253,10 @@ bool InitListChecker::CheckFlexibleArrayInit(const InitializedEntity &Entity,
22532253 return FlexArrayDiag != diag::ext_flexible_array_init;
22542254}
22552255
2256+ static bool isInitializedStructuredList(const InitListExpr *StructuredList) {
2257+ return StructuredList && StructuredList->getNumInits() == 1U;
2258+ }
2259+
22562260void InitListChecker::CheckStructUnionTypes(
22572261 const InitializedEntity &Entity, InitListExpr *IList, QualType DeclType,
22582262 CXXRecordDecl::base_class_const_range Bases, RecordDecl::field_iterator Field,
@@ -2499,8 +2503,7 @@ void InitListChecker::CheckStructUnionTypes(
24992503 StructuredList, StructuredIndex);
25002504 InitializedSomething = true;
25012505 InitializedFields.insert(*Field);
2502-
2503- if (RD->isUnion() && StructuredList) {
2506+ if (RD->isUnion() && isInitializedStructuredList(StructuredList)) {
25042507 // Initialize the first field within the union.
25052508 StructuredList->setInitializedFieldInUnion(*Field);
25062509 }
@@ -2585,7 +2588,7 @@ void InitListChecker::CheckStructUnionTypes(
25852588 CheckImplicitInitList(MemberEntity, IList, Field->getType(), Index,
25862589 StructuredList, StructuredIndex);
25872590
2588- if (RD->isUnion() && StructuredList) {
2591+ if (RD->isUnion() && isInitializedStructuredList( StructuredList) ) {
25892592 // Initialize the first field within the union.
25902593 StructuredList->setInitializedFieldInUnion(*Field);
25912594 }
0 commit comments