c++: Fix error-recovery with requires expression [PR99500]

This fixes an ICE on invalid code where one of the parameters was
error_mark_node and thus resetting its DECL_CONTEXT crashed.

gcc/cp/ChangeLog:

	PR c++/99500
	* parser.c (cp_parser_requirement_parameter_list): Handle
	error_mark_node.

gcc/testsuite/ChangeLog:

	PR c++/99500
	* g++.dg/cpp2a/concepts-err3.C: New test.
This commit is contained in:
Marek Polacek 2021-03-09 20:55:14 -05:00
parent 96ccb32543
commit bd9b262fa9
2 changed files with 9 additions and 2 deletions

View file

@ -28839,8 +28839,11 @@ cp_parser_requirement_parameter_list (cp_parser *parser)
if (parm == void_list_node || parm == explicit_void_list_node)
break;
tree decl = TREE_VALUE (parm);
DECL_CONTEXT (decl) = NULL_TREE;
CONSTRAINT_VAR_P (decl) = true;
if (decl != error_mark_node)
{
DECL_CONTEXT (decl) = NULL_TREE;
CONSTRAINT_VAR_P (decl) = true;
}
}
return parms;

View file

@ -0,0 +1,4 @@
// PR c++/99500
// { dg-do compile { target c++20 } }
bool b = requires (bool a, int a) { requires true; }; // { dg-error "conflicting declaration" }