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.

llvm-svn: 221661
This commit is contained in:
Richard Smith 2014-11-11 03:28:50 +00:00
parent a0d5643610
commit ea97e36dfc
2 changed files with 13 additions and 8 deletions

View File

@ -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;

View File

@ -55,10 +55,9 @@ template<int ...N> 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>();