Skip to content
Snippets Groups Projects
Commit 3ba5be16 authored by Patrick Palka's avatar Patrick Palka
Browse files

c++: ttp TEMPLATE_DECL equivalence [PR112737]


Here during declaration matching we undesirably consider the two TT{42}
CTAD expressions to be non-equivalent ultimately because for CTAD
placeholder equivalence we compare the TEMPLATE_DECLs via pointer identity,
and here the corresponding TEMPLATE_DECLs for TT are different since
they're from different scopes.  On the other hand, the corresponding
TEMPLATE_TEMPLATE_PARMs are deemed equivalent according to cp_tree_equal
(since they have the same position and template parameters).  This turns
out to be the root cause of some of the xtreme-header modules regressions.

So this patch relaxes ttp CTAD placeholder equivalence accordingly, by
comparing the TEMPLATE_TEMPLATE_PARM instead of the TEMPLATE_DECL.  It
turns out this issue also affects function template-id equivalence as
with g<TT> in the second testcase, so it makes sense to relax TEMPLATE_DECL
equivalence more generally in cp_tree_equal.  In passing this patch
improves ctp_hasher::hash for CTAD placeholders, so that they don't
all get the same hash.

	PR c++/112737

gcc/cp/ChangeLog:

	* pt.cc (iterative_hash_template_arg) <case TEMPLATE_DECL>:
	Adjust hashing to match cp_tree_equal.
	(ctp_hasher::hash): Also hash CLASS_PLACEHOLDER_TEMPLATE.
	* tree.cc (cp_tree_equal) <case TEMPLATE_DECL>: Return true
	for ttp TEMPLATE_DECLs if their TEMPLATE_TEMPLATE_PARMs are
	equivalent.
	* typeck.cc (structural_comptypes) <case TEMPLATE_TYPE_PARM>:
	Use cp_tree_equal to compare CLASS_PLACEHOLDER_TEMPLATE.

gcc/testsuite/ChangeLog:

	* g++.dg/template/ttp42.C: New test.
	* g++.dg/template/ttp43.C: New test.

Reviewed-by: default avatarJason Merrill <jason@redhat.com>
parent a886a906
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment