@@ -2251,6 +2251,10 @@ bool InitListChecker::CheckFlexibleArrayInit(const InitializedEntity &Entity,
22512251 return FlexArrayDiag != diag::ext_flexible_array_init;
22522252}
22532253
2254+ static bool isInitializedStructuredList (const InitListExpr *StructuredList) {
2255+ return StructuredList && StructuredList->getNumInits () == 1U ;
2256+ }
2257+
22542258void InitListChecker::CheckStructUnionTypes (
22552259 const InitializedEntity &Entity, InitListExpr *IList, QualType DeclType,
22562260 CXXRecordDecl::base_class_const_range Bases, RecordDecl::field_iterator Field,
@@ -2497,8 +2501,7 @@ void InitListChecker::CheckStructUnionTypes(
24972501 StructuredList, StructuredIndex);
24982502 InitializedSomething = true ;
24992503 InitializedFields.insert (*Field);
2500-
2501- if (RD->isUnion () && StructuredList) {
2504+ if (RD->isUnion () && isInitializedStructuredList (StructuredList)) {
25022505 // Initialize the first field within the union.
25032506 StructuredList->setInitializedFieldInUnion (*Field);
25042507 }
@@ -2583,7 +2586,7 @@ void InitListChecker::CheckStructUnionTypes(
25832586 CheckImplicitInitList (MemberEntity, IList, Field->getType (), Index,
25842587 StructuredList, StructuredIndex);
25852588
2586- if (RD->isUnion () && StructuredList) {
2589+ if (RD->isUnion () && isInitializedStructuredList ( StructuredList) ) {
25872590 // Initialize the first field within the union.
25882591 StructuredList->setInitializedFieldInUnion (*Field);
25892592 }
0 commit comments