@@ -868,13 +868,19 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity,
868
868
869
869
if (const RecordType *RType = ILE->getType ()->getAs <RecordType>()) {
870
870
const RecordDecl *RDecl = RType->getDecl ();
871
- if (RDecl->isUnion () && ILE->getInitializedFieldInUnion ()) {
871
+ if (RDecl->isUnion () && ILE->getInitializedFieldInUnion ())
872
872
FillInEmptyInitForField (0 , ILE->getInitializedFieldInUnion (), Entity, ILE,
873
873
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
+ }
874
883
} else {
875
- assert ((!RDecl->isUnion () || !isa<CXXRecordDecl>(RDecl) ||
876
- !cast<CXXRecordDecl>(RDecl)->hasInClassInitializer ()) &&
877
- " We should have computed initialized fields already" );
878
884
// The fields beyond ILE->getNumInits() are default initialized, so in
879
885
// order to leave them uninitialized, the ILE is expanded and the extra
880
886
// fields are then filled with NoInitExpr.
@@ -2296,7 +2302,6 @@ void InitListChecker::CheckStructUnionTypes(
2296
2302
return ;
2297
2303
}
2298
2304
}
2299
- llvm_unreachable (" Couldn't find in-class initializer" );
2300
2305
}
2301
2306
2302
2307
// Value-initialize the first member of the union that isn't an unnamed
0 commit comments