The pre-increment/pre-decrement grammar in C++ differs from that in C,
but we were parsing the C grammar. Handle the C++ grammar
appropriately. Fixes PR7794.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110445 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 589bf4a..ec92f08 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -568,7 +568,7 @@
// If this expression is limited to being a unary-expression, the parent can
// not start a cast expression.
ParenParseOption ParenExprType =
- isUnaryExpression ? CompoundLiteral : CastExpr;
+ (isUnaryExpression && !getLang().CPlusPlus)? CompoundLiteral : CastExpr;
TypeTy *CastTy;
SourceLocation LParenLoc = Tok.getLocation();
SourceLocation RParenLoc;
@@ -702,10 +702,14 @@
case tok::kw___null:
return Actions.ActOnGNUNullExpr(ConsumeToken());
break;
- case tok::plusplus: // unary-expression: '++' unary-expression
- case tok::minusminus: { // unary-expression: '--' unary-expression
+ case tok::plusplus: // unary-expression: '++' unary-expression [C99]
+ case tok::minusminus: { // unary-expression: '--' unary-expression [C99]
+ // C++ [expr.unary] has:
+ // unary-expression:
+ // ++ cast-expression
+ // -- cast-expression
SourceLocation SavedLoc = ConsumeToken();
- Res = ParseCastExpression(true);
+ Res = ParseCastExpression(!getLang().CPlusPlus);
if (!Res.isInvalid())
Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, move(Res));
return move(Res);