From patchwork Mon Nov 20 02:54:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 166924 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1948000vqn; Sun, 19 Nov 2023 18:54:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6uogcRDiu2nXOB1sSRKSAAHeJ0c/h0BdFqLA2ebeA6jsrNeW4BETo2b2qL/3/aGxBxzBX X-Received: by 2002:ad4:5f85:0:b0:672:7fe3:7aae with SMTP id jp5-20020ad45f85000000b006727fe37aaemr9315670qvb.56.1700448886653; Sun, 19 Nov 2023 18:54:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700448886; cv=pass; d=google.com; s=arc-20160816; b=d2AvqMoiwZpBsDyYNjsInUVTv/DWTKPNKnBcqRL5BgLJSI/rDcVCmmOYyHQfslvep9 +cl8WV0xVBTWFY75AiygSWa/nEBckRs2W9y0to5VOf4mMsX+TtT8SFlxuQl3uIwfREuN cVlffbRWzT6SyoVoKJ1FZbKMzpofaxewALgAigTO44p3y31Qj1gOKWSuTPplXgQk6n+n J3iiSbaZ0corbyre8bsSjDTG/r7U/DFkf3FdZAuYOE7ukVEX2fP9RjoS8NYzqW84YP7U CDXTWAdQ8/NSCgU1PeLA4odsSOBZTLLuQgSqgoZj5sA4Yj2jJhNdN+f1VB5cyu6omAG4 9lQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=pZePPF8RxqFBn4Io1yO7J8cCIwaOjZzMeJ3pa9LS9nY=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=0ExT1sQpJoURmoAPy4U34E/WeRC+c4vdZRjAu8+FJr9XFl5SItXbZw+PUPAlOGwLR5 WB3Z9EO63PGkZTLqTvRyXOSJ4agC7WMPKV8Su1TQX99uYBfh/s75jhId+RHFigGh0JBh wHGWWl8fYVfAY0aeXgs9pcu+jyg5FsuNx/QXN1fsAc5rFE5GqY4DMpQtqLHzOr4pFaUP E2zD6xPsANfmvRnQ8EWy144+1OlEOPl8M8GG4HQx7EJG4C/67PW/yZ25XTJaDRdLksav D7QWqC2LSkz3sgSxVdTT3hbRYtDwrusOaucuzccl645QJ8G3hh14RwJqdJvR9Tn3nKPD K+wA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="eT1/NKbW"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c11-20020ad45aeb000000b00677f974b49asi6440376qvh.429.2023.11.19.18.54.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 18:54:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="eT1/NKbW"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E54D387542B for ; Mon, 20 Nov 2023 02:54:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8BB6A383F190 for ; Mon, 20 Nov 2023 02:54:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BB6A383F190 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8BB6A383F190 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700448862; cv=none; b=l94iNG8eNLAH5v/4/z90ftO+R5xiu+kXAYdY4TSA9+8hee5jqfpf4aFbqRuRIN7GzVj8N4IECX/BxpewlfZ1/Mi126AEnixNWn7FusOTJy1s5rzPYjl4LRVbL8gNcYgHSMo6Nbm7dgoVeJtV34ymJI2NQbHjTI/cTnyGFpSjheo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700448862; c=relaxed/simple; bh=wVGewccKY//6+0oQWPw3zKdIJhGgoAnRT4t2gOD556Q=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=RnJi5n6oE0gdkkTQC5phggwgeF1X4lMXQyYb6XH2jaBgCL73hVrxS6gUGgktecChPPDtigJOwCsyWwx4HZigQ3iZCHHU3J42g2VhY0CLdKa616gJEUffLeP8dKBeXFgku4JfFCnusxHCLOydYaRhRVDEDqOFru7qf3aQlQxUbjg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700448860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pZePPF8RxqFBn4Io1yO7J8cCIwaOjZzMeJ3pa9LS9nY=; b=eT1/NKbW74tJHXDcBuHi6EPyXK62sWdTLlDRomXnK3n/47chd2t6dYDwZKy5H6d6srFDRs Wos30x4E4gtDKyix4axxpdUmmg3Hmz8RKNeHl074U+MSZRCEa1FA8642NMCQmnT+3n62Hb RFDU7HKb/1sYJeGoH6urmfKwipft+CA= Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-Oa8QlTYwOpezLKTtuCItWw-1; Sun, 19 Nov 2023 21:54:19 -0500 X-MC-Unique: Oa8QlTYwOpezLKTtuCItWw-1 Received: by mail-yb1-f200.google.com with SMTP id 3f1490d57ef6-d9b9aeb4962so4749467276.3 for ; Sun, 19 Nov 2023 18:54:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700448858; x=1701053658; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pZePPF8RxqFBn4Io1yO7J8cCIwaOjZzMeJ3pa9LS9nY=; b=fCBfX16empr7KcmZwYyFuapc6fXYVhUar/n8FfBUstyqh2oRQMDuK289AvgRw/OAWR n9MvwKsXvw06YwKjnnPM4WJFLTYlOJiiMcp6NGOMFMYjRD4lROXaxsvJuK2Ziqe9Pc7G KnzUhj8f9gq5SOjwybp8ntHEsL0VWZ0rFTuYmf89sMHTEDycjymIKDZvtuYQTwNFpfUj WfTfnVBLOe23/C0mplpH59xoI8t8lfirta/9x3/WfLAGdCmZR2ZDuq+o4ejJV7aEMraT 6QKdA+pL4QmWV0k5D/xVF9vz6NQ5ZWkjRSVB0FrbD54wSL8aFPnyzNhZiuOci+YSmYEJ L/cg== X-Gm-Message-State: AOJu0Ywp4q28Ys9fdiJvfn9wr19impDEijuzTnQ75il6AQH5T2FdpsSW LW3Yth4CDLQXDOjZ85PVuelCeZwj6AOGB7xkpSzLjxiteicYWxRCM0Yoe/uC3ThAD6agu2mviTq snnVDzegM8HwA90NwwYMO3bNUopPbG1fOAuZJXCWJMTJWaeG1jPxbRv2mOpIITp9ZGGAYUlXuvA == X-Received: by 2002:a25:f821:0:b0:da0:caba:9017 with SMTP id u33-20020a25f821000000b00da0caba9017mr5945161ybd.16.1700448858457; Sun, 19 Nov 2023 18:54:18 -0800 (PST) X-Received: by 2002:a25:f821:0:b0:da0:caba:9017 with SMTP id u33-20020a25f821000000b00da0caba9017mr5945149ybd.16.1700448858012; Sun, 19 Nov 2023 18:54:18 -0800 (PST) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id t2-20020a0cef02000000b0066d23395d27sm2579080qvr.123.2023.11.19.18.54.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 18:54:17 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: compare one level of template parms Date: Sun, 19 Nov 2023 21:54:15 -0500 Message-Id: <20231120025415.2938041-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783049891870908951 X-GMAIL-MSGID: 1783049891870908951 Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- 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 | 94 +++++++++++++++++++--------------------------------- 1 file changed, 35 insertions(+), 59 deletions(-) base-commit: 0d734c79387191005c909c54c7556a88254c401b prerequisite-patch-id: b424bed5ac33d406c713411784f1797effc63375 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; }