Index: lib/Parse/ParseExpr.cpp =================================================================== --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -2514,7 +2514,10 @@ } } else if (Tok.is(tok::ellipsis) && isFoldOperator(NextToken().getKind())) { - return ParseFoldExpression(ExprResult(), T); + Result = ParseFoldExpression(ExprResult(), T); + if (!Result.isInvalid()) + Result = ParsePostfixExpressionSuffix(Result.get()); + return Result; } else if (isTypeCast) { // Parse the expression-list. InMessageExpressionRAIIObject InMessage(*this, false); @@ -2526,8 +2529,12 @@ // 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(ArgExprs[0], T); + NextToken().is(tok::ellipsis)) { + Result = ParseFoldExpression(ArgExprs[0], T); + if (!Result.isInvalid()) + Result = ParsePostfixExpressionSuffix(Result.get()); + return Result; + } ExprType = SimpleExpr; Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(), @@ -2544,8 +2551,12 @@ } ExprType = SimpleExpr; - if (isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis)) - return ParseFoldExpression(Result, T); + if (isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis)) { + Result = ParseFoldExpression(Result, T); + if (!Result.isInvalid()) + Result = ParsePostfixExpressionSuffix(Result.get()); + return Result; + } // Don't build a paren expression unless we actually match a ')'. if (!Result.isInvalid() && Tok.is(tok::r_paren)) Index: test/Parser/cxx1z-fold-expressions.cpp =================================================================== --- test/Parser/cxx1z-fold-expressions.cpp +++ test/Parser/cxx1z-fold-expressions.cpp @@ -60,3 +60,21 @@ } static_assert(nestedFoldOperator<3, 1>() == 1); + +// A fold-expression is a primary-expression. +template +constexpr auto castSum(Ts... Args) { + return (T)(Args + ...).Value; // expected-error{{member reference base type 'int' is not a structure or union}} +} + +void prim() { + castSum(1, 2); + // expected-note@-1{{in instantiation of function template specialization}} + + struct Number { + int Value; + constexpr Number operator+(Number Rhs) const { return {Rhs.Value + Value}; } + }; + + static_assert(castSum(Number{1}, Number{2}) == 3); +}