diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -2109,8 +2109,8 @@ bool ParseParenExprOrCondition(StmtResult *InitStmt, Sema::ConditionResult &CondResult, SourceLocation Loc, Sema::ConditionKind CK, - bool MissingOK, SourceLocation *LParenLoc, - SourceLocation *RParenLoc); + SourceLocation &LParenLoc, + SourceLocation &RParenLoc); StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc); StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc); StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc); diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -1270,20 +1270,20 @@ /// should try to recover harder. It returns false if the condition is /// successfully parsed. Note that a successful parse can still have semantic /// errors in the condition. -/// Additionally, if LParenLoc and RParenLoc are non-null, it will assign -/// the location of the outer-most '(' and ')', respectively, to them. +/// Additionally, it will assign the location of the outer-most '(' and ')', +/// to LParenLoc and RParenLoc, respectively. bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt, Sema::ConditionResult &Cond, SourceLocation Loc, - Sema::ConditionKind CK, bool MissingOK, - SourceLocation *LParenLoc, - SourceLocation *RParenLoc) { + Sema::ConditionKind CK, + SourceLocation &LParenLoc, + SourceLocation &RParenLoc) { BalancedDelimiterTracker T(*this, tok::l_paren); T.consumeOpen(); SourceLocation Start = Tok.getLocation(); if (getLangOpts().CPlusPlus) { - Cond = ParseCXXCondition(InitStmt, Loc, CK, MissingOK); + Cond = ParseCXXCondition(InitStmt, Loc, CK, false); } else { ExprResult CondExpr = ParseExpression(); @@ -1292,7 +1292,7 @@ Cond = Sema::ConditionError(); else Cond = Actions.ActOnCondition(getCurScope(), Loc, CondExpr.get(), CK, - MissingOK); + /*MissingOK=*/false); } // If the parser was confused by the condition and we don't have a ')', try to @@ -1312,18 +1312,13 @@ Actions.PreferredConditionType(CK)); if (!CondExpr.isInvalid()) Cond = Actions.ActOnCondition(getCurScope(), Loc, CondExpr.get(), CK, - MissingOK); + /*MissingOK=*/false); } // Either the condition is valid or the rparen is present. T.consumeClose(); - - if (LParenLoc != nullptr) { - *LParenLoc = T.getOpenLocation(); - } - if (RParenLoc != nullptr) { - *RParenLoc = T.getCloseLocation(); - } + LParenLoc = T.getOpenLocation(); + RParenLoc = T.getCloseLocation(); // Check for extraneous ')'s to catch things like "if (foo())) {". We know // that all callers are looking for a statement after the condition, so ")" @@ -1499,7 +1494,7 @@ if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc, IsConstexpr ? Sema::ConditionKind::ConstexprIf : Sema::ConditionKind::Boolean, - /*MissingOK=*/false, &LParen, &RParen)) + LParen, RParen)) return StmtError(); if (IsConstexpr) @@ -1694,8 +1689,7 @@ SourceLocation LParen; SourceLocation RParen; if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc, - Sema::ConditionKind::Switch, - /*MissingOK=*/false, &LParen, &RParen)) + Sema::ConditionKind::Switch, LParen, RParen)) return StmtError(); StmtResult Switch = Actions.ActOnStartOfSwitchStmt( @@ -1785,8 +1779,7 @@ SourceLocation LParen; SourceLocation RParen; if (ParseParenExprOrCondition(nullptr, Cond, WhileLoc, - Sema::ConditionKind::Boolean, - /*MissingOK=*/false, &LParen, &RParen)) + Sema::ConditionKind::Boolean, LParen, RParen)) return StmtError(); // C99 6.8.5p5 - In C99, the body of the while statement is a scope, even if