[cfe-commits] r72394 - in /cfe/trunk: lib/Parse/ParseExprCXX.cpp test/Parser/cxx-ambig-paren-expr.cpp

Eli Friedman eli.friedman at gmail.com
Mon May 25 12:41:44 PDT 2009


Author: efriedma
Date: Mon May 25 14:41:42 2009
New Revision: 72394

URL: http://llvm.org/viewvc/llvm-project?rev=72394&view=rev
Log:
PR4122: Tweak the ambiguity handling to handle (S())() correctly.  I've 
left out handling for stuff like (S())++ for the moment.


Modified:
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/test/Parser/cxx-ambig-paren-expr.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=72394&r1=72393&r2=72394&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Mon May 25 14:41:42 2009
@@ -1088,12 +1088,17 @@
     ParseAs = CompoundLiteral;
   } else {
     bool NotCastExpr;
-    // Try parsing the cast-expression that may follow.
-    // If it is not a cast-expression, NotCastExpr will be true and no token
-    // will be consumed.
-    Result = ParseCastExpression(false/*isUnaryExpression*/,
-                                 false/*isAddressofOperand*/,
-                                 NotCastExpr);
+    // FIXME: Special-case ++ and --: "(S())++;" is not a cast-expression
+    if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) {
+      NotCastExpr = true;
+    } else {
+      // Try parsing the cast-expression that may follow.
+      // If it is not a cast-expression, NotCastExpr will be true and no token
+      // will be consumed.
+      Result = ParseCastExpression(false/*isUnaryExpression*/,
+                                   false/*isAddressofOperand*/,
+                                   NotCastExpr);
+    }
 
     // If we parsed a cast-expression, it's really a type-id, otherwise it's
     // an expression.

Modified: cfe/trunk/test/Parser/cxx-ambig-paren-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-ambig-paren-expr.cpp?rev=72394&r1=72393&r2=72394&view=diff

==============================================================================
--- cfe/trunk/test/Parser/cxx-ambig-paren-expr.cpp (original)
+++ cfe/trunk/test/Parser/cxx-ambig-paren-expr.cpp Mon May 25 14:41:42 2009
@@ -16,4 +16,11 @@
   typedef int *PT;
   // Make sure stuff inside the parens are parsed only once (only one warning).
   x = (PT()[(int){1}]); // expected-warning {{compound literals}}
+
+  // Special case: empty parens is a call, not an expression
+  struct S{int operator()();};
+  (S())();
+
+  // FIXME: Special case: "++" is postfix here, not prefix
+  // (S())++;
 }





More information about the cfe-commits mailing list