aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-12-12 06:35:28 +0000
committerChris Lattner <sabre@nondot.org>2008-12-12 06:35:28 +0000
commitff871fb8f9c5906a4dee78afd81f60c3837e16cb (patch)
tree259d53adfda1902a4a77665409773538f94c05f9
parent15ff1110c96a26c9315142d407c1f29d86a5ad1f (diff)
use smarter error recovery for do/while.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60933 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Parse/Parser.h3
-rw-r--r--lib/Parse/ParseStmt.cpp11
2 files changed, 9 insertions, 5 deletions
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index bb0a76e4ea..fafaac5954 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -640,7 +640,8 @@ private:
OwningStmtResult ParseDefaultStatement();
OwningStmtResult ParseCompoundStatement(bool isStmtExpr = false);
OwningStmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
- bool ParseParenExprOrCondition(OwningExprResult &CondExp);
+ bool ParseParenExprOrCondition(OwningExprResult &CondExp,
+ bool OnlyAllowCondition = false);
OwningStmtResult ParseIfStatement();
OwningStmtResult ParseSwitchStatement();
OwningStmtResult ParseWhileStatement();
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 45092aa612..ed4563bb6f 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -416,7 +416,7 @@ Parser::OwningStmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
/// ParseParenExprOrCondition:
/// [C ] '(' expression ')'
-/// [C++] '(' condition ')'
+/// [C++] '(' condition ')' [not allowed if OnlyAllowCondition=true]
///
/// This function parses and performs error recovery on the specified condition
/// or expression (depending on whether we're in C++ or C mode). This function
@@ -425,7 +425,8 @@ Parser::OwningStmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
/// 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.
-bool Parser::ParseParenExprOrCondition(OwningExprResult &CondExp) {
+bool Parser::ParseParenExprOrCondition(OwningExprResult &CondExp,
+ bool OnlyAllowCondition) {
SourceLocation LParenLoc = ConsumeParen();
if (getLang().CPlusPlus)
@@ -769,8 +770,10 @@ Parser::OwningStmtResult Parser::ParseDoStatement() {
return StmtError();
}
- // Parse the condition.
- OwningExprResult Cond(ParseSimpleParenExpression());
+ // Parse the parenthesized condition.
+ OwningExprResult Cond(Actions);
+ ParseParenExprOrCondition(Cond, true);
+
DoScope.Exit();
if (Cond.isInvalid() || Body.isInvalid())