The grammar for GNU typeof in C requires an expression to be
parenthesized, unlike in C++, e.g.,
C has: typeof ( expression)
C++ has: typeof unary-expression
So, once we've parsed a parenthesized expression after typeof, we
should only go on to parse the postfix expression suffix if we're in
C++. Fixes <rdar://problem/8237491>.
llvm-svn: 109606
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 40748a7..589bf4a 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1170,10 +1170,13 @@
return ExprEmpty();
}
- // If this is a parenthesized expression, it is the start of a
- // unary-expression, but doesn't include any postfix pieces. Parse these
- // now if present.
- Operand = ParsePostfixExpressionSuffix(move(Operand));
+ if (getLang().CPlusPlus || OpTok.isNot(tok::kw_typeof)) {
+ // GNU typeof in C requires the expression to be parenthesized. Not so for
+ // sizeof/alignof or in C++. Therefore, the parenthesized expression is
+ // the start of a unary-expression, but doesn't include any postfix
+ // pieces. Parse these now if present.
+ Operand = ParsePostfixExpressionSuffix(move(Operand));
+ }
}
// If we get here, the operand to the typeof/sizeof/alignof was an expresion.