@@ -2158,8 +2158,10 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
21582158 // for-range-declaration next.
21592159 bool MightBeForRangeStmt = !ForRangeInfo.ParsedForRangeDecl ();
21602160 ColonProtectionRAIIObject ColonProtection (*this , MightBeForRangeStmt);
2161+ SourceLocation SecondPartStart = Tok.getLocation ();
2162+ Sema::ConditionKind CK = Sema::ConditionKind::Boolean;
21612163 SecondPart = ParseCXXCondition (
2162- nullptr , ForLoc, Sema::ConditionKind::Boolean ,
2164+ nullptr , ForLoc, CK ,
21632165 // FIXME: recovery if we don't see another semi!
21642166 /* MissingOK=*/ true , MightBeForRangeStmt ? &ForRangeInfo : nullptr ,
21652167 /* EnterForConditionScope*/ true );
@@ -2178,6 +2180,19 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
21782180 << FixItHint::CreateRemoval (EmptyInitStmtSemiLoc);
21792181 }
21802182 }
2183+
2184+ if (SecondPart.isInvalid ()) {
2185+ ExprResult CondExpr = Actions.CreateRecoveryExpr (
2186+ SecondPartStart,
2187+ Tok.getLocation () == SecondPartStart ? SecondPartStart
2188+ : PrevTokLocation,
2189+ {}, Actions.PreferredConditionType (CK));
2190+ if (!CondExpr.isInvalid ())
2191+ SecondPart = Actions.ActOnCondition (getCurScope (), ForLoc,
2192+ CondExpr.get (), CK,
2193+ /* MissingOK=*/ false );
2194+ }
2195+
21812196 } else {
21822197 // We permit 'continue' and 'break' in the condition of a for loop.
21832198 getCurScope ()->AddFlags (Scope::BreakScope | Scope::ContinueScope);
0 commit comments