@@ -868,13 +868,19 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity,
868868
869869 if (const RecordType *RType = ILE->getType ()->getAs <RecordType>()) {
870870 const RecordDecl *RDecl = RType->getDecl ();
871- if (RDecl->isUnion () && ILE->getInitializedFieldInUnion ()) {
871+ if (RDecl->isUnion () && ILE->getInitializedFieldInUnion ())
872872 FillInEmptyInitForField (0 , ILE->getInitializedFieldInUnion (), Entity, ILE,
873873 RequiresSecondPass, FillWithNoInit);
874+ else if (RDecl->isUnion () && isa<CXXRecordDecl>(RDecl) &&
875+ cast<CXXRecordDecl>(RDecl)->hasInClassInitializer ()) {
876+ for (auto *Field : RDecl->fields ()) {
877+ if (Field->hasInClassInitializer ()) {
878+ FillInEmptyInitForField (0 , Field, Entity, ILE, RequiresSecondPass,
879+ FillWithNoInit);
880+ break ;
881+ }
882+ }
874883 } else {
875- assert ((!RDecl->isUnion () || !isa<CXXRecordDecl>(RDecl) ||
876- !cast<CXXRecordDecl>(RDecl)->hasInClassInitializer ()) &&
877- " We should have computed initialized fields already" );
878884 // The fields beyond ILE->getNumInits() are default initialized, so in
879885 // order to leave them uninitialized, the ILE is expanded and the extra
880886 // fields are then filled with NoInitExpr.
@@ -2296,7 +2302,6 @@ void InitListChecker::CheckStructUnionTypes(
22962302 return ;
22972303 }
22982304 }
2299- llvm_unreachable (" Couldn't find in-class initializer" );
23002305 }
23012306
23022307 // Value-initialize the first member of the union that isn't an unnamed
0 commit comments