From: Richard Smith Date: Tue, 11 Nov 2014 03:28:50 +0000 (+0000) Subject: Fix parsing of fold-expressions within a cast expression. We parse the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ecb1dc51d3cc67618018f8a956d062618408ab7b;p=clang Fix parsing of fold-expressions within a cast expression. We parse the parenthesized expression a bit differently in this case, just in case the commas have special meaning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221661 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 6913de9fa1..f4eef81175 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -2203,24 +2203,30 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, Diag(Tok, diag::err_expected_lbrace_in_compound_literal); return ExprError(); } + } else if (Tok.is(tok::ellipsis) && + isFoldOperator(NextToken().getKind())) { + return ParseFoldExpression(ExprResult(), T); } else if (isTypeCast) { // Parse the expression-list. InMessageExpressionRAIIObject InMessage(*this, false); - + ExprVector ArgExprs; CommaLocsTy CommaLocs; if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) { + // FIXME: If we ever support comma expressions as operands to + // fold-expressions, we'll need to allow multiple ArgExprs here. + if (ArgExprs.size() == 1 && isFoldOperator(Tok.getKind()) && + NextToken().is(tok::ellipsis)) + return ParseFoldExpression(Result, T); + ExprType = SimpleExpr; Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(), ArgExprs); } - } else if (Tok.is(tok::ellipsis) && - isFoldOperator(NextToken().getKind())) { - return ParseFoldExpression(ExprResult(), T); } else { InMessageExpressionRAIIObject InMessage(*this, false); - + Result = ParseExpression(MaybeTypeCast); ExprType = SimpleExpr; diff --git a/test/SemaTemplate/cxx1z-fold-expressions.cpp b/test/SemaTemplate/cxx1z-fold-expressions.cpp index 3934f011a3..8bb79113fa 100644 --- a/test/SemaTemplate/cxx1z-fold-expressions.cpp +++ b/test/SemaTemplate/cxx1z-fold-expressions.cpp @@ -55,10 +55,9 @@ template void empty_with_base() { extern int k; (k = ... = N); // expected-warning{{unused}} - // FIXME: We misparse these. The first one looks a lot loke a declaration; - // it's not clear what's happening in the second one. void (k = ... = N); // expected-error {{expected ')'}} expected-note {{to match}} - (void) (k = ... = N); // expected-error {{expected ')'}} expected-note {{to match}} + void ((k = ... = N)); + (void) (k = ... = N); } template void empty_with_base<>(); // expected-note {{in instantiation of}} template void empty_with_base<1>();