]> granicus.if.org Git - clang/commitdiff
PR19751: (T())++ is not a cast-expression.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 Jul 2014 00:11:48 +0000 (00:11 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 15 Jul 2014 00:11:48 +0000 (00:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213022 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
lib/Parse/ParseExprCXX.cpp
test/Parser/cxx-casting.cpp

index 4a1742c2c086d41ec156b2c0b400f5f0b19d8c0b..0e4dfb91ad5d2d42a18f32c25177b836cd27101d 100644 (file)
@@ -863,7 +863,12 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
     //     ++ 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;
index 3d1925c25d355b20ceddd65b459b2e6eb2e73eaf..83121a8b1a2db8506c3781dcfda4a6bb3b336cb5 100644 (file)
@@ -2952,7 +2952,6 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
     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 {
index 55309a13560862c8f23d303c25825ed256c695e4..d2c97b88b809c7d4f6491b939f28f3e2a7d2790c 100644 (file)
@@ -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 ';'}}