From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 1AD29386D616; Mon, 20 Nov 2023 02:54:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AD29386D616 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700448873; bh=bVDjYOAhNFcR7oDetmc1RMyW+raLpxbt+X1InnRLWJM=; h=From:To:Subject:Date:From; b=RqIJXgt9Olt3sATDtVTRU/jOSw9IduPssGjc5px2VWjvE9OaJ/gNF58gn80ggac1b B3f058tPWnv8mr09vjIlb+aDJQmJ4//gpwZvOgeg+lKXjijVqN9bRC+aK56RSmW/xf t7fUMrhHHPW5OZEZY6TNMZ6UdgGblaUSzGrAqiYs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-5606] c++: compare one level of template parms X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/trunk X-Git-Oldrev: c51eafc1a185f7ad00820f11a7aa7bf4a82093fa X-Git-Newrev: e85c596ae2d1e5f5b769b5af4c0a8e7d055e40d7 Message-Id: <20231120025433.1AD29386D616@sourceware.org> Date: Mon, 20 Nov 2023 02:54:33 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e85c596ae2d1e5f5b769b5af4c0a8e7d055e40d7 commit r14-5606-ge85c596ae2d1e5f5b769b5af4c0a8e7d055e40d7 Author: Jason Merrill Date: Fri Nov 17 17:17:32 2023 -0500 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. Diff: --- gcc/cp/pt.cc | 94 ++++++++++++++++++++++-------------------------------------- 1 file changed, 35 insertions(+), 59 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1de9d3eb44f..ed681afb5d4 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 (parms1); + tree t2 = TREE_VALUE (parms2); + int i; + + 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; + + for (i = 0; i < TREE_VEC_LENGTH (t2); ++i) { - tree t1 = TREE_VALUE (p1); - tree t2 = TREE_VALUE (p2); - int i; + tree parm1 = TREE_VALUE (TREE_VEC_ELT (t1, i)); + tree parm2 = TREE_VALUE (TREE_VEC_ELT (t2, i)); - gcc_assert (TREE_CODE (t1) == TREE_VEC); - gcc_assert (TREE_CODE (t2) == TREE_VEC); + /* 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_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2)) + if (TREE_CODE (parm1) != TREE_CODE (parm2)) 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)); - - /* 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) == 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 (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 list1 = TREE_VALUE (p1); - tree list2 = TREE_VALUE (p2); - - 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; - } - - p1 = TREE_CHAIN (p1); - p2 = TREE_CHAIN (p2); + 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; }