aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/tree.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2024-02-01 13:17:48 -0500
committerPatrick Palka <ppalka@redhat.com>2024-02-01 13:17:48 -0500
commit3ba5be16a2be3eaedf2870ca1e25cfe826945948 (patch)
tree80ffe11525affcc16c60e4849b6cf8d88e467e44 /gcc/cp/tree.cc
parenta886a90625a4ba5e1cc3270e69735cc4fe51f19c (diff)
downloadgcc-3ba5be16a2be3eaedf2870ca1e25cfe826945948.zip
gcc-3ba5be16a2be3eaedf2870ca1e25cfe826945948.tar.gz
gcc-3ba5be16a2be3eaedf2870ca1e25cfe826945948.tar.bz2
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: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp/tree.cc')
-rw-r--r--gcc/cp/tree.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 77f57e0..5c8c05d 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -4084,11 +4084,15 @@ cp_tree_equal (tree t1, tree t2)
}
return false;
+ case TEMPLATE_DECL:
+ if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
+ && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
+ return cp_tree_equal (TREE_TYPE (t1), TREE_TYPE (t2));
+ /* Fall through. */
case VAR_DECL:
case CONST_DECL:
case FIELD_DECL:
case FUNCTION_DECL:
- case TEMPLATE_DECL:
case IDENTIFIER_NODE:
case SSA_NAME:
case USING_DECL: