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.129.124]) by sourceware.org (Postfix) with ESMTPS id 85EC63882052 for ; Thu, 13 Jun 2024 17:00:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85EC63882052 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 85EC63882052 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718298011; cv=none; b=CdybTPuFnNnXK9AC6OyU68s3nR3LcJnLbmHx/90PLjvcnxWIgx5Pt+y6cwbnqyD2BOGp70YlA2yuFEw5edVZil331W+w9PH6mhk5xspR6uLsp/Tz7CslTxtv1C53pqMPKA2xIxv86PRVh1/IOfD87wUrYpNMfXZZOXfWdDWA3pg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718298011; c=relaxed/simple; bh=Y4u+eL+RD54sGv0j4xj0I7dDNhKMZajPEFLOoI+yN8s=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=twKRZuG9Hc/af1j3yuaGghfqvAeb9VQAHgD3lJu9UN0i6b06n5eyOgQZiHGtWK9QtCqM4iBlAyhtYzfyR3UstV7mY9KmZnhgPXFmdm7u35LBgIICYu7WZY0LavOhrOlL4kablcNi4YSGpUE+g18Z2jNG6Aez9/tPUI8kSyO9Uds= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718298009; 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=NuGdFhDrH8t8LrbSuq8YxSJ+WXdQ2V5MMe8peYljWZE=; b=Tfyn9UW666QANiIX4VXBjraq7XpLU0PnT4Ut+R5UveEGAYubQ3QmC8zT8BdfOEmy/3S8Oc xbudjTvQTIEXYIEoTy4DGimXrdSLjVgF89fVzgvKMuOqetYKbBzl4EZ1BE7MK1mYnStWjQ MM8jEoG/4RQpVgQWtAqy8WkQ7v4dcSo= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-83-nHYcJRS8OQK2ZhKKV322ug-1; Thu, 13 Jun 2024 13:00:07 -0400 X-MC-Unique: nHYcJRS8OQK2ZhKKV322ug-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7954f774295so131552285a.2 for ; Thu, 13 Jun 2024 10:00:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718298007; x=1718902807; 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=NuGdFhDrH8t8LrbSuq8YxSJ+WXdQ2V5MMe8peYljWZE=; b=kKTNx07ouH248zdBa1Wlqn0W3KjEP0Ilt0fgzHV1hYeA4gcF7u/CftWo41zjqB3MVP xHPnpCeUXheZT4a2CUlWhnp0GiKWr5MU040mCu4jIn3Z07OlNpVJaQPOQfjFgMnrT8xY 15CMcBpP+SJt3SsKpI1ZAIsjAxSL8HDjyUvUGCHcyoDB+Vuq/oZACNB4C8Df4GLUS8la 4TC+DxQ/em0Lu9UazWPN8AfqY/iVNrToWNiRe0k7I9wFMvuqh964/IGjwCYrYqWBm4ad jIckSGZxHiLhVsAEnoxCBF2Oq+xkhEez4Tsn1vyWowG854cor2k/rMpuyeRZ7Z8RAoq+ sztw== X-Forwarded-Encrypted: i=1; AJvYcCVkJOq/lmvch9F4vMrdBgaMSrPq/sLOL0P59ScOoRI7M/ClkJC4qqV6FYBojgixdrBZuezq3kQ/tCivREoj9+KV7YDeHuQTrg== X-Gm-Message-State: AOJu0Yxt6kVKvskQcOZvFqDVMruQBzk/HS6fRnQRLck5vokYa8lUfd1e q1GHv4vCVqL64N21+OvMll4T4575ae0OzQc/hWOC5tJv0mt5EVZA1HjZpfZM99vfWoilBvI98mn eCervQE9SOn9nWjgeU4RkB05+1ZIxmjzqA+w5VDTCo9qw+SMcQ6Umf9M= X-Received: by 2002:a05:620a:4001:b0:797:8549:492 with SMTP id af79cd13be357-798d2430c4fmr8378385a.35.1718298005061; Thu, 13 Jun 2024 10:00:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFT4auk8bn03HQHMFCMRc1ENnvYfVLEHNADkNVUwg6lY9R6kOG5HZNdJ3OwRPrzmzKPTM76kQ== X-Received: by 2002:a05:620a:4001:b0:797:8549:492 with SMTP id af79cd13be357-798d2430c4fmr8369085a.35.1718298004181; Thu, 13 Jun 2024 10:00:04 -0700 (PDT) Received: from [192.168.1.130] (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798abc105cfsm67121285a.81.2024.06.13.10.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 10:00:03 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 13 Jun 2024 13:00:03 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: alias CTAD and copy deduction guide [PR115198] In-Reply-To: Message-ID: <2e40d426-4683-1e96-4a6f-902763ddf26a@idea> References: <20240523180653.755621-1-ppalka@redhat.com> <720e4cad-2401-4208-a401-177a1c29b336@redhat.com> <35ad2db8-bafe-4772-96c3-7467ae27da9b@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.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,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 List-Id: On Thu, 13 Jun 2024, Jason Merrill wrote: > On 6/13/24 11:05, Patrick Palka wrote: > > On Thu, 23 May 2024, Jason Merrill wrote: > > > > > On 5/23/24 17:42, Patrick Palka wrote: > > > > On Thu, 23 May 2024, Jason Merrill wrote: > > > > > > > > > On 5/23/24 14:06, Patrick Palka wrote: > > > > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look > > > > > > OK for trunk/14? > > > > > > > > > > > > -- >8 -- > > > > > > > > > > > > Here we're neglecting to update DECL_NAME during the alias CTAD > > > > > > guide > > > > > > transformation, which causes copy_guide_p to return false for the > > > > > > transformed copy deduction guide since DECL_NAME is still __dguide_C > > > > > > with TREE_TYPE C but it should be __dguide_A with TREE_TYPE > > > > > > A > > > > > > (equivalently C). This ultimately results in ambiguity > > > > > > during > > > > > > overload resolution between the copy deduction guide vs copy ctor > > > > > > guide. > > > > > > > > > > > > This patch makes us update DECL_NAME of a transformed guide > > > > > > accordingly > > > > > > during alias CTAD. This eventually needs to be done for inherited > > > > > > CTAD > > > > > > too, but it's not clear what identifier to use there since it has to > > > > > > be > > > > > > unique for each derived/base pair. For > > > > > > > > > > > > template struct A { ... }; > > > > > > template struct B : A { using A > > > > > T>::A; } > > > > > > > > > > > > at first glance it'd be reasonable to give inherited guides a name > > > > > > of > > > > > > __dguide_B with TREE_TYPE A, but since that name is > > > > > > already > > > > > > used B's own guides its TREE_TYPE is already B. > > > > > > > > > > Why can't it be the same __dguide_B with TREE_TYPE B? > > > > > > > > Ah because copy_guide_p relies on TREE_TYPE in order to recognize a copy > > > > deduction guide, and with that TREE_TYPE it would still incorrectly > > > > return false for an inherited copy deduction guide, e.g. > > > > > > > > A(A) -> A > > > > > > > > gets transformed into > > > > > > > > B(A) -> B > > > > > > > > and A != B so copy_guide_p returns false. > > > > > > Hmm, that seems correct; the transformed candidate is not the copy > > > deduction > > > guide for B. > > > > By https://eel.is/c++draft/over.match.class.deduct#3.4 it seems that a > > class template can now have multiple copy deduction guides with inherited > > CTAD: the derived class's own copy guide, along with the transformed copy > > guides of its eligible base classes. Do we want to follow the standard > > precisely here, or should we maybe restrict the copy-guideness propagation > > to alias CTAD only? > > The latter, I think; it seems nonsensical to have multiple copy guides. Sounds good, so for inherited CTAD it should suffice to use __dguide_B as the name (where B is the derived class), like so? -- >8 -- Subject: [PATCH] c++: alias CTAD and copy deduction guide [PR115198] Here we're neglecting to update DECL_NAME during the alias CTAD guide transformation, which causes copy_guide_p to return false for the transformed copy deduction guide since DECL_NAME is still __dguide_C with TREE_TYPE C but it should be __dguide_A with TREE_TYPE A (equivalently C). This ultimately results in ambiguity during overload resolution between the copy deduction guide vs copy ctor guide. This patch makes us update DECL_NAME of a transformed guide accordingly during alias/inherited CTAD. PR c++/115198 gcc/cp/ChangeLog: * pt.cc (alias_ctad_tweaks): Update DECL_NAME of a transformed guide. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias22.C: New test. --- gcc/cp/pt.cc | 6 +++++- .../g++.dg/cpp2a/class-deduction-alias22.C | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias22.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 607753ae6b7..daa8ac386dc 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -30342,13 +30342,14 @@ alias_ctad_tweaks (tree tmpl, tree uguides) any). */ enum { alias, inherited } ctad_kind; - tree atype, fullatparms, utype; + tree atype, fullatparms, utype, name; if (TREE_CODE (tmpl) == TEMPLATE_DECL) { ctad_kind = alias; atype = TREE_TYPE (tmpl); fullatparms = DECL_TEMPLATE_PARMS (tmpl); utype = DECL_ORIGINAL_TYPE (DECL_TEMPLATE_RESULT (tmpl)); + name = dguide_name (tmpl); } else { @@ -30356,6 +30357,8 @@ alias_ctad_tweaks (tree tmpl, tree uguides) atype = NULL_TREE; fullatparms = TREE_PURPOSE (tmpl); utype = TREE_VALUE (tmpl); + name = dguide_name (TPARMS_PRIMARY_TEMPLATE + (INNERMOST_TEMPLATE_PARMS (fullatparms))); } tsubst_flags_t complain = tf_warning_or_error; @@ -30451,6 +30454,7 @@ alias_ctad_tweaks (tree tmpl, tree uguides) } if (g == error_mark_node) continue; + DECL_NAME (g) = name; if (nfparms == 0) { /* The targs are all non-dependent, so g isn't a template. */ diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias22.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias22.C new file mode 100644 index 00000000000..9c6c841166a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias22.C @@ -0,0 +1,14 @@ +// PR c++/115198 +// { dg-do compile { target c++20 } } + +template +struct C { + C() = default; + C(const C&) = default; +}; + +template +using A = C; + +C c; +A a = c; // { dg-bogus "ambiguous" } -- 2.45.2.492.gd63586cb31 > > Jason > > > > > But it just occurred to me that this TREE_TYPE clobbering of the > > > > __dguide_foo identifier already happens if we have two class templates > > > > with the same name in different namespaces, since the identifier > > > > contains only the terminal name. Maybe this suggests that we should > > > > use a tree flag to track whether a guide is the copy deduction guide > > > > instead of setting TREE_TYPE of DECL_NAME? > > > > > > Good point. > > > > > > Jason > > > > > > > > > >