From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 6DCA33858D35 for ; Wed, 31 Jan 2024 21:03:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DCA33858D35 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 6DCA33858D35 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=1706734993; cv=none; b=MFcBbtL3TmBhJmZd7R4TIwcO0J4Au9fwsi8AAryYfcbmSGgapctMqc6soFhW4ebzt2Ww/1dUbFw1H79o0N4U9GckqKIat+R+e79Si6DmpDU96xMGDDkdQ1C2R7t8Gilv6Y2pWnlCdCQFBirieNnjTVOy+8tgd0HcpsB4VwMfvTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706734993; c=relaxed/simple; bh=M4ktHHMT6kE0HmX6OBmq8ES88g1KNojQJhv/v3phtl4=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=mFhdCKVxfHWqoqc0UaOILXr/hAeaNPt59F4AYb3RDQIF83VEfLbR1kuY+ImsI25htDaovjzJZCLJ+RWR8ZbVCEYaGZeIE8mqa6CO1LmgHIVuXvc/Pj9+pVG7tTFev1XTMSII6OEuGtJkfBnrwO4d4ahXz66fI9hGN3tBrIjw2gc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706734991; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=SWPBRzv8k1re/mg8c2a5IJhuDvcxIK/DL5u+wLlA/7Q=; b=DSg8wgw0peeCe11kK11pNc3akkNhrb7gNJmpO3AY7YDiv9YK8WUAGa78IwVRjNMVKFvHpP ZX4YsSRXSxsHXdGMKDiDaXo7DhAVVIJJ1HyrBjav/1BluTCtToeIkvEv9ad3B1a7m3BqMX tttl/tNtzewq96b+mah5Gju9DGCQutk= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-ad9IjqaGO9Sr2bPwiT-zxA-1; Wed, 31 Jan 2024 16:03:06 -0500 X-MC-Unique: ad9IjqaGO9Sr2bPwiT-zxA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-68c50d32297so2672216d6.0 for ; Wed, 31 Jan 2024 13:03:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706734985; x=1707339785; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SWPBRzv8k1re/mg8c2a5IJhuDvcxIK/DL5u+wLlA/7Q=; b=qkieRWw78EhLyACLUx+1BDOxDY3AeHMRAoJXhlcde94ARTl7UqguSyqsVyTRBw3ulj o+KL/cVPdTZKNSlGJwv1CVZhmLSwTxII6Rhvv+fyQNvn8tbD/9DiQL9lHYSbj5mnaw2o aEDlvhmSNIazEIYelcvQ8yCWxUODWfeOJI0JdWq7X5DgyYYdyzKqK3LoTjhODRGaV952 4e32eEbQzLsSwV+rycpYTiL5+suuUznsuNIL2nOQ6Aw/wb4sM50xAJf8PiO307UZluSo omYBuVAJxWlCUBrPTiWPg8ZVb+cBtYSC12YJOfIc+aKudf4tSZ0aHR0wdZ9ohOrT0pCK /frw== X-Gm-Message-State: AOJu0Yz29jrA69jLypDplY4EZ2gbR2CtQvtorsCB3FwsWbAo+JFoSTF4 tJR8a6rD95JS7svP71Mi2cu1fS9CFnTg4agAzFQoJ+eeDoFFOnZVurMQbkUnqdl1OPjJC6VlBRD buWUBljXGOOu/f739DPRvQKXY/2coChPGkkXM79aTiDWNTJuBf33U4TE= X-Received: by 2002:ad4:5ae9:0:b0:686:aa78:dd11 with SMTP id c9-20020ad45ae9000000b00686aa78dd11mr513033qvh.37.1706734985392; Wed, 31 Jan 2024 13:03:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUlSLq1fiAV2EAcROpYtdK5LrU+D13mBhcV2N+FiMS3NdaB8J7XmSHQ6Lw5/4etUkvp2x5pQ== X-Received: by 2002:ad4:5ae9:0:b0:686:aa78:dd11 with SMTP id c9-20020ad45ae9000000b00686aa78dd11mr513006qvh.37.1706734985074; Wed, 31 Jan 2024 13:03:05 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c25-20020a056214071900b006869dae6ef2sm4251668qvz.106.2024.01.31.13.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:03:04 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 31 Jan 2024 16:03:04 -0500 (EST) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: ttp CTAD equivalence [PR112737] In-Reply-To: <673370b1-e7bc-4d8c-8d09-748d20c0bbb7@redhat.com> Message-ID: <619f5b57-9598-762c-7e38-a9e6c98a6401@idea> References: <20240131171245.1102131-1-ppalka@redhat.com> <673370b1-e7bc-4d8c-8d09-748d20c0bbb7@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.7 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_H5,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,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 List-Id: On Wed, 31 Jan 2024, Jason Merrill wrote: > On 1/31/24 12:12, Patrick Palka wrote: > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > > trunk? > > > > -- >8 -- > > > > 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 (which uses > > 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 (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. > > > > We don't have this ttp equivalence issue in other contexts because either > > the TEMPLATE_TEMPLATE_PARM is used instead of the TEMPLATE_DECL already > > (e.g. when a ttp is used as a targ), or the equivalence logic is relaxed > > (e.g. for bound ttps), it seems. > > > > So this patch relaxes ttp CTAD placeholder equivalence accordingly, by > > comparing the TEMPLATE_TEMPLATE_PARM instead of the TEMPLATE_DECL. The > > ctp_hasher doesn't need to be adjusted since it currently doesn't include > > CLASS_PLACEHOLDER_TEMPLATE in the hash anyway. > > Maybe put this handling in cp_tree_equal and call it from here? Does > iterative_hash_template_arg need something similar? I was hoping cp_tree_equal would never be called for a ttp TEMPLATE_DECL after this patch, and so it wouldn't matter either way, but it turns out to matter for a function template-id: template class, class T> void g(T); template class TT, class T> decltype(g(T{})) f(T); // #1 template class TT, class T> decltype(g(T{})) f(T); // redeclaration of #1 template struct A { A(T); }; int main() { f(0); } Here we represent TT in g as a TEMPLATE_DECL because it's not until coercion that convert_template_argument turns it into a TEMPLATE_TEMPLATE_PARM, but of course we can't coerce until the call is non-dependent and we know which function we're calling. (So TT within a class, variable or alias template-id would be represented as a TEMPLATE_TEMPLATE_PARM since we can do coercion ahead of time in that case.) So indeed it seems desirable to handle this in cp_tree_equal... like so? Bootstrap and regtest nearly finished. -- >8 -- PR c++/112737 gcc/cp/ChangeLog: * pt.cc (iterative_hash_template_arg) : Adjust hashing to match cp_tree_equal. (ctp_hasher::hash): Also hash CLASS_PLACEHOLDER_TEMPLATE. * tree.cc (cp_tree_equal) : Return true for ttp TEMPLATE_DECLs if their TEMPLATE_TEMPLATE_PARMs are equivalent. * typeck.cc (structural_comptypes) : Use cp_tree_equal to compare CLASS_PLACEHOLDER_TEMPLATE. gcc/testsuite/ChangeLog: * g++.dg/template/ttp42.C: New test. * g++.dg/template/ttp42a.C: New test. --- gcc/cp/pt.cc | 9 +++++++++ gcc/cp/tree.cc | 6 +++++- gcc/cp/typeck.cc | 4 ++-- gcc/testsuite/g++.dg/template/ttp42.C | 14 ++++++++++++++ gcc/testsuite/g++.dg/template/ttp42a.C | 18 ++++++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/ttp42.C create mode 100644 gcc/testsuite/g++.dg/template/ttp42a.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 5871cb668d0..ca454758ca7 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -1816,6 +1816,13 @@ iterative_hash_template_arg (tree arg, hashval_t val) } return iterative_hash_template_arg (TREE_TYPE (arg), val); + case TEMPLATE_DECL: + if (DECL_TEMPLATE_TEMPLATE_PARM_P (arg)) + return iterative_hash_template_arg (TREE_TYPE (arg), val); + else + /* Hash it like any other declaration. */ + break; + case TARGET_EXPR: return iterative_hash_template_arg (TARGET_EXPR_INITIAL (arg), val); @@ -4499,6 +4506,8 @@ struct ctp_hasher : ggc_ptr_hash hashval_t val = iterative_hash_object (code, 0); val = iterative_hash_object (TEMPLATE_TYPE_LEVEL (t), val); val = iterative_hash_object (TEMPLATE_TYPE_IDX (t), val); + if (TREE_CODE (t) == TEMPLATE_TYPE_PARM) + val = iterative_hash_template_arg (CLASS_PLACEHOLDER_TEMPLATE (t), val); if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM) val = iterative_hash_template_arg (TYPE_TI_ARGS (t), val); --comparing_specializations; diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 77f57e0f9ac..5c8c05dc168 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: diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index a15eda3f5f8..87109e63138 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -1573,8 +1573,8 @@ structural_comptypes (tree t1, tree t2, int strict) return false; /* If T1 and T2 don't represent the same class template deduction, they aren't equal. */ - if (CLASS_PLACEHOLDER_TEMPLATE (t1) - != CLASS_PLACEHOLDER_TEMPLATE (t2)) + if (!cp_tree_equal (CLASS_PLACEHOLDER_TEMPLATE (t1), + CLASS_PLACEHOLDER_TEMPLATE (t2))) return false; /* Constrained 'auto's are distinct from parms that don't have the same constraints. */ diff --git a/gcc/testsuite/g++.dg/template/ttp42.C b/gcc/testsuite/g++.dg/template/ttp42.C new file mode 100644 index 00000000000..da08e857fc5 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp42.C @@ -0,0 +1,14 @@ +// PR c++/112737 +// { dg-do compile { target c++17 } } + +template class TT> +decltype(TT{42}) f(); // #1 + +template class TT> +decltype(TT{42}) f(); // redeclaration of #1 + +template struct A { A(T); }; + +int main() { + f(); +} diff --git a/gcc/testsuite/g++.dg/template/ttp42a.C b/gcc/testsuite/g++.dg/template/ttp42a.C new file mode 100644 index 00000000000..e890deda3a3 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp42a.C @@ -0,0 +1,18 @@ +// PR c++/112737 +// A version of ttp42.C using a function template-id instead of ttp CTAD. +// { dg-do compile { target c++11 } } + +template class, class T> +void g(T); + +template class TT, class T> +decltype(g(T{})) f(T); // #1 + +template class TT, class T> +decltype(g(T{})) f(T); // redeclaration of #1 + +template struct A { A(T); }; + +int main() { + f(0); +} -- 2.43.0.493.gbc7ee2e5e1