diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-23 18:11:15 +0000 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-23 18:11:15 +0000 |
| commit | b77ebd749af6171a565c19139849fc7d8d4209e4 (patch) | |
| tree | 124ac4e509017b031febc648fd1cd2d9d0ac75e9 /clang/lib/Parse/ParseExprCXX.cpp | |
| parent | 38bb1c15fdf76ab0632c0062d06867cb6c93c7af (diff) | |
| download | bcm5719-llvm-b77ebd749af6171a565c19139849fc7d8d4209e4.tar.gz bcm5719-llvm-b77ebd749af6171a565c19139849fc7d8d4209e4.zip | |
Revert r273548, "Rearrange condition handling so that semantic checks on a condition variable"
as it caused a regression in -Wfor-loop-analysis.
llvm-svn: 273589
Diffstat (limited to 'clang/lib/Parse/ParseExprCXX.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseExprCXX.cpp | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 00f20e5e7b7..b0740970d88 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1726,19 +1726,27 @@ Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { /// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt] /// '=' assignment-expression /// +/// \param ExprOut if the condition was parsed as an expression, the parsed +/// expression. +/// +/// \param DeclOut if the condition was parsed as a declaration, the parsed +/// declaration. +/// /// \param Loc The location of the start of the statement that requires this /// condition, e.g., the "for" in a for loop. /// /// \param ConvertToBoolean Whether the condition expression should be /// converted to a boolean value. /// -/// \returns The parsed condition. -Sema::ConditionResult Parser::ParseCXXCondition(SourceLocation Loc, - Sema::ConditionKind CK) { +/// \returns true if there was a parsing, false otherwise. +bool Parser::ParseCXXCondition(ExprResult &ExprOut, + Decl *&DeclOut, + SourceLocation Loc, + bool ConvertToBoolean) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition); cutOffParsing(); - return Sema::ConditionError(); + return true; } ParsedAttributesWithRange attrs(AttrFactory); @@ -1748,11 +1756,16 @@ Sema::ConditionResult Parser::ParseCXXCondition(SourceLocation Loc, ProhibitAttributes(attrs); // Parse the expression. - ExprResult Expr = ParseExpression(); // expression - if (Expr.isInvalid()) - return Sema::ConditionError(); + ExprOut = ParseExpression(); // expression + DeclOut = nullptr; + if (ExprOut.isInvalid()) + return true; - return Actions.ActOnCondition(getCurScope(), Loc, Expr.get(), CK); + // If required, convert to a boolean value. + if (ConvertToBoolean) + ExprOut + = Actions.ActOnBooleanCondition(getCurScope(), Loc, ExprOut.get()); + return ExprOut.isInvalid(); } // type-specifier-seq @@ -1770,7 +1783,7 @@ Sema::ConditionResult Parser::ParseCXXCondition(SourceLocation Loc, ExprResult AsmLabel(ParseSimpleAsm(&Loc)); if (AsmLabel.isInvalid()) { SkipUntil(tok::semi, StopAtSemi); - return Sema::ConditionError(); + return true; } DeclaratorInfo.setAsmLabel(AsmLabel.get()); DeclaratorInfo.SetRangeEnd(Loc); @@ -1782,9 +1795,8 @@ Sema::ConditionResult Parser::ParseCXXCondition(SourceLocation Loc, // Type-check the declaration itself. DeclResult Dcl = Actions.ActOnCXXConditionDeclaration(getCurScope(), DeclaratorInfo); - if (Dcl.isInvalid()) - return Sema::ConditionError(); - Decl *DeclOut = Dcl.get(); + DeclOut = Dcl.get(); + ExprOut = ExprError(); // '=' assignment-expression // If a '==' or '+=' is found, suggest a fixit to '='. @@ -1804,11 +1816,12 @@ Sema::ConditionResult Parser::ParseCXXCondition(SourceLocation Loc, SourceLocation LParen = ConsumeParen(), RParen = LParen; if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch)) RParen = ConsumeParen(); - Diag(DeclOut->getLocation(), + Diag(DeclOut ? DeclOut->getLocation() : LParen, diag::err_expected_init_in_condition_lparen) << SourceRange(LParen, RParen); } else { - Diag(DeclOut->getLocation(), diag::err_expected_init_in_condition); + Diag(DeclOut ? DeclOut->getLocation() : Tok.getLocation(), + diag::err_expected_init_in_condition); } if (!InitExpr.isInvalid()) @@ -1821,7 +1834,8 @@ Sema::ConditionResult Parser::ParseCXXCondition(SourceLocation Loc, // (This is currently handled by Sema). Actions.FinalizeDeclaration(DeclOut); - return Actions.ActOnConditionVariable(DeclOut, Loc, CK); + + return false; } /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. |

