c++: Fix endless errors on invalid requirement seq [PR97742]

As the testcase shows, if we reach CPP_EOF during parsing of requirement
sequence, we end up with endless loop where we always report invalid
requirement expression, don't consume any token (as we are at eof) and
repeat.

This patch stops the loop when we reach CPP_EOF.

2021-02-12  Jakub Jelinek  <jakub@redhat.com>

	PR c++/97742
	* parser.c (cp_parser_requirement_seq): Stop iterating after reaching
	CPP_EOF.

	* g++.dg/cpp2a/concepts-requires24.C: New test.
This commit is contained in:
Jakub Jelinek 2021-02-12 09:55:46 +01:00
parent 95d94b52ea
commit cf059e1c09
2 changed files with 7 additions and 1 deletions

View File

@ -28807,7 +28807,9 @@ cp_parser_requirement_seq (cp_parser *parser)
tree req = cp_parser_requirement (parser);
if (req != error_mark_node)
result = tree_cons (NULL_TREE, req, result);
} while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE));
}
while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE)
&& cp_lexer_next_token_is_not (parser->lexer, CPP_EOF));
/* If there are no valid requirements, this is not a valid expression. */
if (!result)

View File

@ -0,0 +1,4 @@
// PR c++/97742
// { dg-do compile { target c++20 } }
template <int = requires { true // { dg-error "expected" }