]> granicus.if.org Git - clang/commitdiff
The grammar for GNU typeof in C requires an expression to be
authorDouglas Gregor <dgregor@apple.com>
Wed, 28 Jul 2010 18:22:12 +0000 (18:22 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 28 Jul 2010 18:22:12 +0000 (18:22 +0000)
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>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109606 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
test/Parser/typeof.c

index 40748a7019333e2c5cd10d26f4126a98ce8c7cf1..589bf4a35f8c118dd989f1a274cecfc0ab402b5a 100644 (file)
@@ -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.
index cf0e47a6b1244a23102adaa808fef54d7eda25e0..7953a69fed001a92da6a54dca2c34e9a41a33158 100644 (file)
@@ -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));    
+}