From: Patrick Palka Date: Mon, 10 Jul 2023 14:59:40 +0000 (-0400) Subject: c++: redeclare_class_template and ttps [PR110523] X-Git-Tag: basepoints/gcc-15~7718 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c60368ab5706a870a1a3be190acc4d673672c30;p=thirdparty%2Fgcc.git c++: redeclare_class_template and ttps [PR110523] Now that we cache level-lowered ttps we can end up processing the same ttp multiple times via (multiple calls to) redeclare_class_template, so we can't assume a ttp's DECL_CONTEXT is initially empty. PR c++/110523 gcc/cp/ChangeLog: * pt.cc (redeclare_class_template): Relax the ttp DECL_CONTEXT assert, and downgrade it to a checking assert. gcc/testsuite/ChangeLog: * g++.dg/template/ttp37.C: New test. --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index d7d774fd9e5b..076f788281ef 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -6388,7 +6388,8 @@ redeclare_class_template (tree type, tree parms, tree cons) DECL_CONTEXT of the template for which they are a parameter. */ if (TREE_CODE (parm) == TEMPLATE_DECL) { - gcc_assert (DECL_CONTEXT (parm) == NULL_TREE); + gcc_checking_assert (DECL_CONTEXT (parm) == NULL_TREE + || DECL_CONTEXT (parm) == tmpl); DECL_CONTEXT (parm) = tmpl; } } diff --git a/gcc/testsuite/g++.dg/template/ttp37.C b/gcc/testsuite/g++.dg/template/ttp37.C new file mode 100644 index 000000000000..c5f4e99c20a0 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp37.C @@ -0,0 +1,15 @@ +// PR c++/110523 + +template class> +class basic_json; + +template +struct json_pointer { + template class> + friend class basic_json; +}; + +template struct json_pointer; +template struct json_pointer; +template struct json_pointer; +template struct json_pointer;