From: Richard Smith Date: Tue, 15 Jul 2014 00:11:48 +0000 (+0000) Subject: PR19751: (T())++ is not a cast-expression. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1f3ec3553ce63007802e52bc05acd2e7d33c74f;p=clang PR19751: (T())++ is not a cast-expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213022 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 4a1742c2c0..0e4dfb91ad 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -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; diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 3d1925c25d..83121a8b1a 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -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 { diff --git a/test/Parser/cxx-casting.cpp b/test/Parser/cxx-casting.cpp index 55309a1356..d2c97b88b8 100644 --- a/test/Parser/cxx-casting.cpp +++ b/test/Parser/cxx-casting.cpp @@ -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 ';'}}