This patch fixes PR c++/96437 which is an ICE-on-invalid-code regression
affecting mainline.
This patch has been tested on x86_64-pc-linux-gnu, enabling languages
c and c++, with make bootstrap and make -k check with no new failures.
Ok for mainline?
2022-03-07 Roger Sayle <[email protected]>
gcc/cp/ChangeLog
PR c++/96437
* parser.cc (synthesize_implicit_template_parm): Check that
TREE_VALUE (new_parm) isn't error_mark_node before setting its
DECL_VIRTUAL_P.
gcc/testsuite/ChangeLog
PR c++/96437
* g++.dg/pr96437.C: New test case.
Thanks in advance,
Roger
--
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 03d99ab..992f839 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -48217,7 +48217,8 @@ synthesize_implicit_template_parm (cp_parser *parser,
tree constr)
function template is equivalent to an explicit template.
Note that DECL_ARTIFICIAL is used elsewhere for template parameters. */
- DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true;
+ if (TREE_VALUE (new_parm) != error_mark_node)
+ DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true;
// Chain the new parameter to the list of implicit parameters.
if (parser->implicit_template_parms)
diff --git a/gcc/testsuite/g++.dg/pr96437.C b/gcc/testsuite/g++.dg/pr96437.C
new file mode 100644
index 0000000..00c4141
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr96437.C
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-excess-errors "" } */
+
+template <()> void A(auto){}