r213022 - PR19751: (T())++ is not a cast-expression.

Richard Smith richard-llvm at metafoo.co.uk
Mon Jul 14 17:11:48 PDT 2014


Author: rsmith
Date: Mon Jul 14 19:11:48 2014
New Revision: 213022

URL: http://llvm.org/viewvc/llvm-project?rev=213022&view=rev
Log:
PR19751: (T())++ is not a cast-expression.

Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/test/Parser/cxx-casting.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=213022&r1=213021&r2=213022&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Jul 14 19:11:48 2014
@@ -863,7 +863,12 @@ ExprResult Parser::ParseCastExpression(b
     //     ++ cast-expression
     //     -- cast-expression
     SourceLocation SavedLoc = ConsumeToken();
-    Res = ParseCastExpression(!getLangOpts().CPlusPlus);
+    // One special case is implicitly handled here: if the preceding tokens are
+    // an ambiguous cast expression, such as "(T())++", then we recurse to
+    // determine whether the '++' is prefix or postfix.
+    Res = ParseCastExpression(!getLangOpts().CPlusPlus,
+                              /*isAddressOfOperand*/false, NotCastExpr,
+                              NotTypeCast);
     if (!Res.isInvalid())
       Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
     return Res;

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=213022&r1=213021&r2=213022&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Mon Jul 14 19:11:48 2014
@@ -2952,7 +2952,6 @@ Parser::ParseCXXAmbiguousParenExpression
     ParseAs = CompoundLiteral;
   } else {
     bool 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 {

Modified: cfe/trunk/test/Parser/cxx-casting.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-casting.cpp?rev=213022&r1=213021&r2=213022&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-casting.cpp (original)
+++ cfe/trunk/test/Parser/cxx-casting.cpp Mon Jul 14 19:11:48 2014
@@ -101,5 +101,11 @@ void PR19748() {
   (true ? (B(*)())f : p)();
 }
 
+void PR19751(int n) {
+  struct T { void operator++(int); };
+  (T())++; // ok, not an ill-formed cast to function type
+  (T())++n; // expected-error {{C-style cast from 'int' to 'T ()' is not allowed}}
+}
+
 // PR13619. Must be at end of file.
 int n = reinterpret_cast // expected-error {{expected '<'}} expected-error {{expected ';'}}





More information about the cfe-commits mailing list