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 00CB03858D38 for ; Thu, 23 May 2024 21:42:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00CB03858D38 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 00CB03858D38 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=1716500559; cv=none; b=bH08rsP1RVX/3HBrN94ldgVyrGiBss5z22uOAIF7AnFg4LTpkn4gZpMT1SmM84MBaKeex45lR9Sf7bZ2h65fnHPJmd5epGjJWCsppWN7G2OIwOkihZo1yXsulEifQ6h/AODbWySuySOF0XBIssq3tHctORTpMABB3lMDSguiNZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716500559; c=relaxed/simple; bh=sw12FIp40xI4MenxbpTV1Aa7L5wawyPqW044YPIG1zQ=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=daOoTkBn65O7vNVh0AYQUEy2Inh6Vy+90iPb4u9fWUO6PwsF7XLB1kmsJ8Zb0agsD4mjEnFKLvnCZMWIdq/YWmZankYFmkGrVoQJolS+FJZnLx67J0JqOZUAu1zVzUHxT9X80XgTTVFxqNiGHByGO5cvJxqGnN/6oS6d+itOAbE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716500556; 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=ICk/btWqquifE9UXS2B/le1mxxGo/U5gp1hgbLSmJYE=; b=G9mwXnRhAI8hJKAFXzNVNAPM6Nag7CM9P0jJWi8v1tKV+rezp9GbVWBlt3Bx6HPIss68XX IcY7qBMlyQTfHVjB1GbKMPPiZF7QiAHvO0DiJokf0gpA4CIHd4bjIwt6LXHyNA82zC1spA ZWSNdyX/tEhigDeDhdzOAsOzs3q3v/I= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-FQ77BF__OL2Zg0NEMwAuKQ-1; Thu, 23 May 2024 17:42:35 -0400 X-MC-Unique: FQ77BF__OL2Zg0NEMwAuKQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-792bd1dc658so74213385a.1 for ; Thu, 23 May 2024 14:42:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716500554; x=1717105354; 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=ICk/btWqquifE9UXS2B/le1mxxGo/U5gp1hgbLSmJYE=; b=wwYLrhapOYpTMnl1N5AynaG4nY9kK4hJ8D2JmYpHuSMdMujSZm6x7SboZmMaTCXqpq 8VLS8mEJPHDwezVGcyASuGaEYiaeK95C8i1P5Rzt0zDX2rRY+bHa6uIZJFk2rOYGEdIe b3qn3J8mcNGoLDujLLRVWQgp+4+K+xkAsINNvtZzXy/nACC1MqP1rV7kJUyqbbmKjc27 dnsXQ9JtC4FyudFISz9bfBXIKzvcPhs/JB83MLaeuvbvagOIgKQbHOZix+p6tfl9UZZr 404Dmtc2/sHYSD+kv0sAcx6/y0Xi3zQb7XCn3+/vxryiev3u0oeJ1KPYs+BwwMT5ikOZ a3JA== X-Forwarded-Encrypted: i=1; AJvYcCXalTBuzC7gSKUd/yMrG0QEBIE8VE/gAFG9A5Og1fNzXlBPjsrp1p4ERRtyVEY2P57JyDFbR7BTQa8MzAX44wFe28NpDDYmWg== X-Gm-Message-State: AOJu0YyI+thUhYHyc5TwaU1KKmn3ykefwaTI8T1jJwP6teau6xJAExE0 D4eq6LfsVeDeHi8wYS2d6eSlEUh09xygn5ytfRYOvdPhqRmai8z6m2CBiTSOiYmDkUtl9Sa8kdk T9gAg5jgkBCCmgVH/O1QLbwirlPdje1VWeZmxiphYDDgI8peob0ngWBw= X-Received: by 2002:a05:620a:288a:b0:790:8656:8427 with SMTP id af79cd13be357-794a08fbe82mr582609985a.7.1716500554434; Thu, 23 May 2024 14:42:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErH0BqwdfEuTM2xO+DBnJuUzGlKsNPE/16s+lvbl0wgBHRbOv23TMt+CZrLWWTheC5+0QjIQ== X-Received: by 2002:a05:620a:288a:b0:790:8656:8427 with SMTP id af79cd13be357-794a08fbe82mr582606685a.7.1716500553994; Thu, 23 May 2024 14:42:33 -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-794abca5934sm4110385a.11.2024.05.23.14.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 14:42:33 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 23 May 2024 17:42:32 -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: <720e4cad-2401-4208-a401-177a1c29b336@redhat.com> Message-ID: References: <20240523180653.755621-1-ppalka@redhat.com> <720e4cad-2401-4208-a401-177a1c29b336@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.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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP 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, 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::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. 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? > > > PR c++/115198 > > > > gcc/cp/ChangeLog: > > > > * pt.cc (alias_ctad_tweaks): Update DECL_NAME of a transformed > > guide during alias CTAD. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/cpp2a/class-deduction-alias22.C: New test. > > --- > > gcc/cp/pt.cc | 9 ++++++++- > > .../g++.dg/cpp2a/class-deduction-alias22.C | 14 ++++++++++++++ > > 2 files changed, 22 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 0c4d96cf768..58873057abc 100644 > > --- a/gcc/cp/pt.cc > > +++ b/gcc/cp/pt.cc > > @@ -30304,13 +30304,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 > > { > > @@ -30318,6 +30319,10 @@ alias_ctad_tweaks (tree tmpl, tree uguides) > > atype = NULL_TREE; > > fullatparms = TREE_PURPOSE (tmpl); > > utype = TREE_VALUE (tmpl); > > + /* FIXME: What name should we give inherited guides? It needs to be > > + unique to the derived/base pair so that we don't clobber an earlier > > + setting of TREE_TYPE. */ > > + name = NULL_TREE; > > } > > tsubst_flags_t complain = tf_warning_or_error; > > @@ -30413,6 +30418,8 @@ alias_ctad_tweaks (tree tmpl, tree uguides) > > } > > if (g == error_mark_node) > > continue; > > + if (name) > > + 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" } > >