Here we accept a bogus expression before a left fold:
Recall that a fold expression looks like:
fold-expression:
( cast-expression fold-operator ... )
( ... fold-operator cast-expression )
( cast-expression fold-operator ... fold-operator cast-expression )
but here we have
( cast-expression ... fold-operator cast-expression )
The best fix seems to just return error_mark_node when we know this code
is invalid, and let the subsequent code report that a ) was expected.
gcc/cp/ChangeLog:
PR c++/86773
* parser.c (cp_parser_fold_expression): Return error_mark_node
if a left fold is preceded by an expression.
gcc/testsuite/ChangeLog:
PR c++/86773
* g++.dg/cpp1z/fold12.C: New test.
// Left fold.
if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
{
+ if (expr1)
+ return error_mark_node;
cp_lexer_consume_token (parser->lexer);
int op = cp_parser_fold_operator (parser);
if (op == ERROR_MARK)
--- /dev/null
+// PR c++/86773
+// { dg-do compile { target c++17 } }
+
+template <typename ... Param>
+auto work(Param && ...param)
+{
+ return ("asda" ... / param); // { dg-error "expected" }
+}
+
+int main()
+{
+ work(1.0, 2.0, 5, 4.0);
+}