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 7344A3858D38 for ; Thu, 23 May 2024 18:06:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7344A3858D38 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 7344A3858D38 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=1716487621; cv=none; b=iqIrjhTdoPuRc8y+DD/Mynla6un+W6AE0O3TTnciEzGv0bZjvlrTHxIoSeNEeLXEzqaqGEe8muXVLMqhVEaMTOrSrtJO48S3ljrlpdX4hcMaFLnvc+BCdPNUXW2UX8mkj9sHeqcvlQLZxvFLFyrC6nuxZ3otdloumlQcw8gFEQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716487621; c=relaxed/simple; bh=oamfMfr9/olyAINRGuGb72teQEACs7MKlIJ2+F0Zkhc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QoSMLJ3SqHnzDlSxcL1xgQ14Oux+BagaXWIk8rGVq9rsAc/Zob4F4D4jQUYvLGNmbG/kBMsmOi638U1R4NLamD2T5p5DbLvToayah0zqG1bXrsjbUbYDhdoIflhjw54C3B6he56QHVI44oX2nJu8YYbzqqA5/XHuTSpGUnzywP0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716487619; 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: content-transfer-encoding:content-transfer-encoding; bh=yzeucO/x63Oe1Wn1xsmd4hLTQeX2XAaPIZe95vwEo40=; b=irAR0CSZUpGHRi85QwMgg49PXJqQicLnFDAyIuq6QtZwtQE5rFGEOA+tvOzze4VPVssFuF VgqKvCIj+VR5jxXtPXS78rfuvF5oRpikQkEmo9nnVJeynQoBII4UljmakEG16UpbrlV147 nro0UYhnTduzOab+XrI6Ma2fM1tVIFU= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-10-Um-1ORotOEuZN9WtjoVBgQ-1; Thu, 23 May 2024 14:06:57 -0400 X-MC-Unique: Um-1ORotOEuZN9WtjoVBgQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-43f95c2f135so5196501cf.0 for ; Thu, 23 May 2024 11:06:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716487616; x=1717092416; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yzeucO/x63Oe1Wn1xsmd4hLTQeX2XAaPIZe95vwEo40=; b=sS9fJu8SmUOQafNoN0oiAqisnauVnZfWwEfnjPvoeOeJSAcVgOrhvNrApKcs2VD7zu kGDozW0a9htFbKr6moNoRZ8Fd8d2htSalKNMtkix9bzyJ5QEF1PTnaWO00S1T90uRuKq A0daKdU1dvb5lyF97A2B79d/Aa3NKDEc08qIaz4+6uaKO6l/9wVnyDN5gV355HUauHZo ru9099Gm6e0e7AmwUIKijJY6+oT3aEbYtqLsSaZoyXBhdWQrdik6+ZDQJrK1dCSqxSOm 4NprftsHmE8gpw/Se9xwJ/hzRvGWiGpJcWS4cnNWbojZr6hkPCrQ61cbUxuzS4Cq9mzw ALvg== X-Gm-Message-State: AOJu0YxsIUei5xGuspZal+7IBak6rz2fiwCdUClsqAeATNVUO+7lNQWU INg0ON4lYJoBYEjMPpDMZmhh2ck0bHx5cetHH0NHHBCJ27BDC/+5eR9KFhPM4WCNTeQB2eXJvW0 jHbqNp53IifVSVhV8qDJcut6tY7b4qs/HlavOgKilt26cKROiKzfgoW0QplpS7oe6hMk8eAla95 M8Izfl4NXQGUsuMm5A6OodqdH3PAfETZUZgszm X-Received: by 2002:a05:622a:509:b0:43b:e48:6512 with SMTP id d75a77b69052e-43f9e1adfeemr73627281cf.45.1716487616066; Thu, 23 May 2024 11:06:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2cazJ0ez6KDEu+rRZhiohtvpayL9mJLEU0Dg6PYQvpn6Z1WDJR9sPyutASJpGMYE8ciwZ8w== X-Received: by 2002:a05:622a:509:b0:43b:e48:6512 with SMTP id d75a77b69052e-43f9e1adfeemr73626841cf.45.1716487615379; Thu, 23 May 2024 11:06:55 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43faab6f6f0sm9417971cf.29.2024.05.23.11.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 11:06:55 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: alias CTAD and copy deduction guide [PR115198] Date: Thu, 23 May 2024 14:06:53 -0400 Message-ID: <20240523180653.755621-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.1.216.g4365c6fcf9 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.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: 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. 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" } -- 2.45.1.216.g4365c6fcf9