From patchwork Mon Mar 4 22:26:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1907919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NOWlkT6L; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TpYH32Vr7z23cm for ; Tue, 5 Mar 2024 09:27:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE944385842F for ; Mon, 4 Mar 2024 22:27:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 CD6F83858C55 for ; Mon, 4 Mar 2024 22:27:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD6F83858C55 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 CD6F83858C55 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=1709591241; cv=none; b=qj+nyYtG67fIFqLxZ5tvNuO5CxTqhxnEyKgptUL3Zl3C3HFfJZtQeVvrgFqyHCXa33OqZn3FGnIdX4uL7pBeLJp/pyLALPMiqnpTVvqyhudOEPE+jwslUFRfJc3irBWwhYEKCxN0zvsjhXWexO0n5/YUzNlt2XOWV6JJ804XvZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709591241; c=relaxed/simple; bh=meFi4kN7sBRgkMfRAPDTkFgqDPK+84HtNwh8OfzfP6w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lHZ9jDEZXVRG4T8xd+j/p3rSVy/eHqKSkvUnj9vhG9gfkOCRqXwawGvilptEIKVzGPVzfC26GrtH6D2JTDB3+uPNSgb799SqmPnpBxIJRxSUTcV87hnDplLxzLxRX+vvaBUFPPfJu+JVqhXjaz3wb/1XXWV9GXkIW0xcd4XxmKs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709591238; 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=oNOHLBcNeBpDirPK1AEBVfRjgR4B0BB77nEI4QesVyI=; b=NOWlkT6Lt+GfAwrZdPZUuZ8yesn+obUMBx5JXFARFp0GZBtZJtwg8k/sXCTIcSOldBEPeq PEhtUdTOYvcilW/rDYmqYNprkNDcr5O0XwtCgA/rdajuZpiwZcyIcqQ3jztRDo7fDX2IG+ w+R8uamABYXB1sW4l3R1u/qsXcyiJl8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-yMMvy7D-Ni6__QkA7CBJ7w-1; Mon, 04 Mar 2024 17:27:17 -0500 X-MC-Unique: yMMvy7D-Ni6__QkA7CBJ7w-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-42ef6a1b6b6so12297491cf.2 for ; Mon, 04 Mar 2024 14:27:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709591235; x=1710196035; 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=oNOHLBcNeBpDirPK1AEBVfRjgR4B0BB77nEI4QesVyI=; b=AnMka5yIklaiOTN55Z/M5XUTWTpconEJ6PVHHuYltDvljKpQ5tp1UW99PzhrNB78pi GZrWCUo1eaOXa87pEP6UBA0KKglGrBxnowqTpGWrLOQCEdv4eL8tbtFy2bPfmoT3tXen IhfYZS4+/mW1z2HJt0Fvzm7Nnqn1M5ca6PhbGvscKs0eYUqu1EpP3TKrrngX7hmHYojS dZ2ravPm2a33V7HWZrXfeq5a0D4vmTzpKfvjvr302VMzoiwRdqqJMFOh9tj2I1hLcHI8 KaGswEENbt1n1w1wbQbhMSCXEflKhunpV89JXZSUyzRwvm5vjMI2ImdcWP8xDIjTNGiN Xa0g== X-Gm-Message-State: AOJu0YxqrTTLlVMtsjKq9MRt374zGpqiqg3cubJt1pYSI02/hADuVEuP 9l2KvgYJ4ucZZjUv94fG/LGiXEwpuvbFtF0qn5Hdu9Bn4ePD4AWEUegIJJQnzH7VSAh8ytbgC+c 38w89ezvWLzLjTvsfsPa13TB+9jXS/HKp7+5K0nPa/AiY6CBnzP7VZGrMonJSPVurFWaMpblDO9 ca40x4jW8wp8zDmNL3xZ0lIP18NbjLfhVqA+AG X-Received: by 2002:a05:622a:1489:b0:42e:c64f:91b2 with SMTP id t9-20020a05622a148900b0042ec64f91b2mr243250qtx.17.1709591235469; Mon, 04 Mar 2024 14:27:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRu27B2kMi9qyxQZMrWqcVQswZtg5pBSAGXc3zFMn5XjyzHrD/YnXMpyvtBwFqspqhAavMxQ== X-Received: by 2002:a05:622a:1489:b0:42e:c64f:91b2 with SMTP id t9-20020a05622a148900b0042ec64f91b2mr243233qtx.17.1709591235166; Mon, 04 Mar 2024 14:27:15 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id g8-20020ac84dc8000000b0042eed783365sm1706016qtw.40.2024.03.04.14.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 14:27:14 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++/modules: member alias tmpl partial inst [PR103994] Date: Mon, 4 Mar 2024 17:26:53 -0500 Message-ID: <20240304222654.1511204-1-ppalka@redhat.com> X-Mailer: git-send-email 2.44.0.84.gb387623c12 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.1 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, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Alias templates are weird in that their specializations can appear in both decl_specializations and type_specializations. They appear in the latter only at parse time via finish_template_type. This should probably be revisited in GCC 15 since it seems sufficient to store them only in decl_specializations. In the meantime, the below patch makes sure that if a such a specialization is stored in both tables then we don't overwrite in the type code path the TEMPLATE_INFO set by the decl code path (which always runs first). That's because tsubst_template_decl during partial instantiation of a member template sets TI_TEMPLATE of the TYPE_DECL to point to the partially instantiated TEMPLATE_DECL whereas lookup_template_class wants to always point to the most general template. This ends up confusing modules in the testcase below for the partial instantiation A::key_arg -- we decide to stream the TYPE_DECL for this partial instantiation separately from the corresponding TEMPLATE_DECL due to this incorrect TI_TEMPLATE setting. PR c++/103994 gcc/cp/ChangeLog: * pt.cc (lookup_template_class): Don't overwrite TEMPLATE_INFO for an alias template specialization. gcc/testsuite/ChangeLog: * g++.dg/modules/tpl-alias-2_a.H: New test. * g++.dg/modules/tpl-alias-2_b.C: New test. --- gcc/cp/pt.cc | 7 ++++++- gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H | 15 +++++++++++++++ gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H create mode 100644 gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c4bc54a8fdb..ce2d53fe762 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -10431,7 +10431,12 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context, } /* Build template info for the new specialization. */ - SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist)); + if (DECL_ALIAS_TEMPLATE_P (gen_tmpl)) + /* Already properly set by instantiate_template (or + tsubst_template_decl). */ + gcc_assert (DECL_TEMPLATE_INFO (TYPE_NAME (t))); + else + SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist)); elt.spec = t; slot = type_specializations->find_slot_with_hash (&elt, hash, INSERT); diff --git a/gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H b/gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H new file mode 100644 index 00000000000..76917f778e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/tpl-alias-2_a.H @@ -0,0 +1,15 @@ +// PR c++/103994 +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } + +template +struct A { + template using key_arg = int; +}; + +struct B { + template + void f() { + using type = A::key_arg; + } +}; diff --git a/gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C b/gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C new file mode 100644 index 00000000000..44fa5f42757 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/tpl-alias-2_b.C @@ -0,0 +1,9 @@ +// PR c++/103994 +// { dg-additional-options -fmodules-ts } + +import "tpl-alias-2_a.H"; + +int main() { + B b; + b.f(); +}