summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-07-28 18:22:12 +0000
committerDouglas Gregor <dgregor@apple.com>2010-07-28 18:22:12 +0000
commit5dc055350ead45dca64b5e6d542569baab330b35 (patch)
treef421942ca00ea39bddbfd4182ca92fcd639f9c2c /clang
parent59fba9d2b92b401b4937c5123490e071000ca596 (diff)
downloadbcm5719-llvm-5dc055350ead45dca64b5e6d542569baab330b35.tar.gz
bcm5719-llvm-5dc055350ead45dca64b5e6d542569baab330b35.zip
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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Parse/ParseExpr.cpp11
-rw-r--r--clang/test/Parser/typeof.c7
2 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 40748a70193..589bf4a35f8 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1170,10 +1170,13 @@ Parser::ParseExprAfterTypeofSizeofAlignof(const Token &OpTok,
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.
diff --git a/clang/test/Parser/typeof.c b/clang/test/Parser/typeof.c
index cf0e47a6b12..7953a69fed0 100644
--- a/clang/test/Parser/typeof.c
+++ b/clang/test/Parser/typeof.c
@@ -17,3 +17,10 @@ static void test() {
int xx;
int *i;
}
+
+// <rdar://problem/8237491>
+void test2() {
+ int a;
+ short b;
+ __typeof__(a) (*f)(__typeof__(b));
+}
OpenPOWER on IntegriCloud