From e85c596ae2d1e5f5b769b5af4c0a8e7d055e40d7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 17 Nov 2023 17:17:32 -0500 Subject: c++: compare one level of template parms There should never be a reason to compare more than one level of template parameters; additional levels are for the enclosing context, which is either irrelevant (for a template template parameter) or already compared (for a member template). Also, the comp_template_parms handling of type parameters was wrongly checking for TEMPLATE_TYPE_PARM when a type parameter appears here as a TYPE_DECL. gcc/cp/ChangeLog: * pt.cc (comp_template_parms): Just one level. (template_parameter_lists_equivalent_p): Likewise. --- gcc/cp/pt.cc | 90 ++++++++++++++++++++++-------------------------------------- 1 file changed, 33 insertions(+), 57 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1de9d3e..ed681af 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -3274,53 +3274,40 @@ check_explicit_specialization (tree declarator, int comp_template_parms (const_tree parms1, const_tree parms2) { - const_tree p1; - const_tree p2; - if (parms1 == parms2) return 1; - for (p1 = parms1, p2 = parms2; - p1 != NULL_TREE && p2 != NULL_TREE; - p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2)) - { - tree t1 = TREE_VALUE (p1); - tree t2 = TREE_VALUE (p2); - int i; + tree t1 = TREE_VALUE (parms1); + tree t2 = TREE_VALUE (parms2); + int i; - gcc_assert (TREE_CODE (t1) == TREE_VEC); - gcc_assert (TREE_CODE (t2) == TREE_VEC); + gcc_assert (TREE_CODE (t1) == TREE_VEC); + gcc_assert (TREE_CODE (t2) == TREE_VEC); - if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2)) - return 0; + if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2)) + return 0; - for (i = 0; i < TREE_VEC_LENGTH (t2); ++i) - { - tree parm1 = TREE_VALUE (TREE_VEC_ELT (t1, i)); - tree parm2 = TREE_VALUE (TREE_VEC_ELT (t2, i)); + for (i = 0; i < TREE_VEC_LENGTH (t2); ++i) + { + tree parm1 = TREE_VALUE (TREE_VEC_ELT (t1, i)); + tree parm2 = TREE_VALUE (TREE_VEC_ELT (t2, i)); - /* If either of the template parameters are invalid, assume - they match for the sake of error recovery. */ - if (error_operand_p (parm1) || error_operand_p (parm2)) - return 1; + /* If either of the template parameters are invalid, assume + they match for the sake of error recovery. */ + if (error_operand_p (parm1) || error_operand_p (parm2)) + return 1; - if (TREE_CODE (parm1) != TREE_CODE (parm2)) - return 0; + if (TREE_CODE (parm1) != TREE_CODE (parm2)) + return 0; - if (TREE_CODE (parm1) == TEMPLATE_TYPE_PARM - && (TEMPLATE_TYPE_PARAMETER_PACK (parm1) - == TEMPLATE_TYPE_PARAMETER_PACK (parm2))) - continue; - else if (!same_type_p (TREE_TYPE (parm1), TREE_TYPE (parm2))) - return 0; - } + if (TREE_CODE (parm1) == TYPE_DECL + && (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm1)) + == TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm2)))) + continue; + else if (!same_type_p (TREE_TYPE (parm1), TREE_TYPE (parm2))) + return 0; } - if ((p1 != NULL_TREE) != (p2 != NULL_TREE)) - /* One set of parameters has more parameters lists than the - other. */ - return 0; - return 1; } @@ -3403,31 +3390,20 @@ template_parameter_lists_equivalent_p (const_tree parms1, const_tree parms2) if (parms1 == parms2) return true; - const_tree p1 = parms1; - const_tree p2 = parms2; - while (p1 != NULL_TREE && p2 != NULL_TREE) - { - tree list1 = TREE_VALUE (p1); - tree list2 = TREE_VALUE (p2); + tree list1 = TREE_VALUE (parms1); + tree list2 = TREE_VALUE (parms2); - if (TREE_VEC_LENGTH (list1) != TREE_VEC_LENGTH (list2)) - return 0; - - for (int i = 0; i < TREE_VEC_LENGTH (list2); ++i) - { - tree parm1 = TREE_VEC_ELT (list1, i); - tree parm2 = TREE_VEC_ELT (list2, i); - if (!template_parameters_equivalent_p (parm1, parm2)) - return false; - } + if (TREE_VEC_LENGTH (list1) != TREE_VEC_LENGTH (list2)) + return 0; - p1 = TREE_CHAIN (p1); - p2 = TREE_CHAIN (p2); + for (int i = 0; i < TREE_VEC_LENGTH (list2); ++i) + { + tree parm1 = TREE_VEC_ELT (list1, i); + tree parm2 = TREE_VEC_ELT (list2, i); + if (!template_parameters_equivalent_p (parm1, parm2)) + return false; } - if ((p1 != NULL_TREE) != (p2 != NULL_TREE)) - return false; - return true; } -- cgit v1.1