[cfe-commits] r109606 - in /cfe/trunk: lib/Parse/ParseExpr.cpp test/Parser/typeof.c

Douglas Gregor dgregor at apple.com
Wed Jul 28 11:22:13 PDT 2010


Author: dgregor
Date: Wed Jul 28 13:22:12 2010
New Revision: 109606

URL: http://llvm.org/viewvc/llvm-project?rev=109606&view=rev
Log:
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>.


Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/test/Parser/typeof.c

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=109606&r1=109605&r2=109606&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Jul 28 13:22:12 2010
@@ -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.

Modified: cfe/trunk/test/Parser/typeof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/typeof.c?rev=109606&r1=109605&r2=109606&view=diff
==============================================================================
--- cfe/trunk/test/Parser/typeof.c (original)
+++ cfe/trunk/test/Parser/typeof.c Wed Jul 28 13:22:12 2010
@@ -17,3 +17,10 @@
   int xx;
   int *i;
 }
+
+// <rdar://problem/8237491>
+void test2() {
+    int a;
+    short b;
+    __typeof__(a) (*f)(__typeof__(b));    
+}





More information about the cfe-commits mailing list