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 80DC53858D38 for ; Thu, 23 May 2024 21:24:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80DC53858D38 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 80DC53858D38 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=1716499449; cv=none; b=bYGPDyBpkP1yDTO8B5eHrbkTVpPQcunt6+6cnvXq1zJAKaU/XGk0CLQ2wWgvOreemxB6zEFDm5cfJZyvjY8s9yEzxRm0rdzvOJekxXVa9jJ7SEgyErBVaLTevZcx97kz4wDoSz7N//ugoZSd0LpanfgKvhnXC+AyZwaTEN6YDWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716499449; c=relaxed/simple; bh=bEaKja++zxrGifj4kR4KjjYkOavZrM59uCz/QzCEwsg=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=N2d6+fBE5dOQmQwRc6i83AcCexudFUUVq0PRNzU5arPBCLMMhSlFjawvUgaBI+1JbHZFFRtEZDwrir1XY/Ji4SAfBQGnYLK9nFFtnSonO9USh4ZEmRtAvgkuvhWSx9bdaGCWBg5/dXU71DF4tg2fMz7T/ligT2Q59/FTGLX3KyA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716499447; 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: in-reply-to:in-reply-to:references:references; bh=VSOkBGgUk/bhqD36c+51jnnplO/p8Te9HQLVdqKnxok=; b=Q8t7cxs7fERDjSOB9QlgjCkqC3ECnFkDDeFeYwQ2qQpr/4x2+CRXO0HlJimjgH2Ct58lI2 qZm34A2FLpU1m81JDgScWyNZTJXVDLzudRmQGe+OZwH8gIkRxrnC7rPgX/ahK1N4bgsnOl Y2Hcpz7rtj0k1gOQ9MqTNF6gSvllZkU= 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-356-aLaVnofPM3u9XAIz95kQSg-1; Thu, 23 May 2024 17:24:05 -0400 X-MC-Unique: aLaVnofPM3u9XAIz95kQSg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-792e037511eso48024285a.2 for ; Thu, 23 May 2024 14:24:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716499445; x=1717104245; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VSOkBGgUk/bhqD36c+51jnnplO/p8Te9HQLVdqKnxok=; b=gVW0kfzywX7kL7pjZtzDMrI2ji9LABms3v3zNwDAsep17xCgviYADXPQ9IklB3AHR7 RQeiY7wyElguknTa9+yRIq5kpS4w9hKIXXc67Fw8S16SuaV33lMQPLVpTWsZLKZ3Smoa 1UruSidVWn1sTkR6J81go+RbcgS2Zs2lFHcKs557ZUCpXYyGnlj8HoyTcW8ZDxb3qYVm S4koHingzf7mLN5ZJ594e8RflJUwmnitPKQDlZEeojvy/NJsXJ/xgzrQwOGVmzaCzelZ atHqVWps5lI/2IGvGuwyYoL2iW4eQPGQV/X/8cvmii4W7ZYQF+kJYX/YBb98Do8ohNBg xlLQ== X-Forwarded-Encrypted: i=1; AJvYcCW9Fat7PCeMyvP3AsNtcYueycLzQOp4zE1paR3NjDwrbO0s7gOvxf7iIHDsrtniWvL3lrQAiFngAUs5fp7vsEhmSFtvK1Db3w== X-Gm-Message-State: AOJu0YzQ/YqAX9V+Hzwoba8iS+HovM2MCPLslJqx9XrJMI9MCXKQyETd 47XuE6q5C8FolT3Vk3YP+49auPnKXcbo+QTPplUFjHTLmHbsfUhC2VyASoMbDmlf14BmHCQ7q6J zrkpSn3fc+S0GT/2XMwZlLkudxDqG1drDeoD78X1HrslfmwiEj2eNFHI= X-Received: by 2002:a05:620a:1581:b0:793:31:d2fd with SMTP id af79cd13be357-794ab08d9e9mr51919385a.5.1716499444617; Thu, 23 May 2024 14:24:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEl5/YEoGjBKUO5LMczR3qQgp/O5hoO557T2XKs0NqY/0gF6Hr6phqqftVpFfvxXBYp/1UTvg== X-Received: by 2002:a05:620a:1581:b0:793:31:d2fd with SMTP id af79cd13be357-794ab08d9e9mr51916185a.5.1716499443915; Thu, 23 May 2024 14:24:03 -0700 (PDT) Received: from [192.168.1.130] (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 af79cd13be357-794abcdb0eesm2636485a.62.2024.05.23.14.24.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 14:24:03 -0700 (PDT) Message-ID: <720e4cad-2401-4208-a401-177a1c29b336@redhat.com> Date: Thu, 23 May 2024 17:24:02 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: alias CTAD and copy deduction guide [PR115198] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20240523180653.755621-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20240523180653.755621-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.3 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 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? > 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" }