c++: GCC accepts junk before fold-expression [PR86773]
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.
This commit is contained in:
parent
dfbadb8ce9
commit
43cb72263f
@ -5138,6 +5138,8 @@ cp_parser_fold_expression (cp_parser *parser, tree expr1)
|
||||
// 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)
|
||||
|
13
gcc/testsuite/g++.dg/cpp1z/fold12.C
Normal file
13
gcc/testsuite/g++.dg/cpp1z/fold12.C
Normal file
@ -0,0 +1,13 @@
|
||||
// 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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user