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.
This commit is contained in:
Patrick Palka 2023-07-10 10:59:40 -04:00
parent 1e2e5713a6
commit 2c60368ab5
2 changed files with 17 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -0,0 +1,15 @@
// PR c++/110523
template<template<class> class>
class basic_json;
template<class>
struct json_pointer {
template<template<class> class>
friend class basic_json;
};
template struct json_pointer<int>;
template struct json_pointer<char>;
template struct json_pointer<long>;
template struct json_pointer<void>;