From patchwork Sat Mar 2 06:54:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1907083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YJbK4pnJ; 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 4Tmwgq1BfMz23l2 for ; Sat, 2 Mar 2024 17:55:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A062385841D for ; Sat, 2 Mar 2024 06:54:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id D1A1B3858D1E for ; Sat, 2 Mar 2024 06:54:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D1A1B3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D1A1B3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709362478; cv=none; b=qzpUhwsNFd8cXTYfHQPeOF5mJ5RMEN3QDj1YY4PpOmLl82cwOIU+X2GUnpLCzugNiHzHf9lLFBBbHFwen4VG0qlF7S+l2+no4C9Gd4LJiv4Vv0Cm/GvpL9ve1kslPZJKRKZoEV/sw/VlfMQASsvG4Sk02C5YDwCQ3ugIHvuo0b0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709362478; c=relaxed/simple; bh=xPavnMF1xk56aYDEVH5WrqU/EIG9F4KbPdVEkF8vf7E=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=fxJma/TmtevQwWZLZtrXXlK0ulES2Ku9fP46ZnodPofEq+bvEX8p3NYGHQJQXaDm9D45Ah2vL35L+fBCJZadv4xkm8H+/4XPwrYv4O0Ra1wSpDQaMg5PNZVcVDZ4/4xiEu0j1m/5gzy15GWyc/pD+Q71JcDYr5SJJ8btEip48SQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6e56da425b5so2269659b3a.0 for ; Fri, 01 Mar 2024 22:54:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709362476; x=1709967276; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4d9xiuN4LY7iKDbklhuE2GsVVG8cMTDO6J/o0g4btX4=; b=YJbK4pnJbaesi6CKvvoySVDoEH4ST2vZIPAbZdbpMdY64EFuP9SBYvohtUcykakH4g mZRzNjWV8LPFq7q402WXmZ0Hh5EOb9ivaE9b65dnRYL5zw57qZfI4K8FPab4PEfSb9vp EJBNSBtCz8cGP4rGU2hnzlDvywSc98vaWd0yXOOczmbjamqlG8jfK6GjY9b1MiZRXTnI rlvcjoOyCBSMqAPzf+1DHH/595fMIIERMfEDVfS4N8dWcSotNdINCyHPIEia2egFqX5A jazNdAC0tM83WOqMNAojMWBv2nIkNmfBonacWihWUHWJzFaKzF8RqoVPi4jzGq2HsWEc dQrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709362476; x=1709967276; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4d9xiuN4LY7iKDbklhuE2GsVVG8cMTDO6J/o0g4btX4=; b=h4NLPOBD/9JXkpv56WCLBxUWfm5aTR9kAqMVn34D/FGKr7HIvpoiNjsXlWo26psVOz drCgjGmfecGGUJTgJuEYn8/DfyPaZXm8AGywCwqD3TDlVUyKDe4hE8/NuQ8wfy7VRkOm dpwwAByc2b3qOpHtT2HeK0zBR1VWl5RjLr/17lLpLpwsPy7EhfUm4nk/tqdl2BStx6yu 1ZmdTOssEohmQlVjCywMDdxMeUEOTph6rV+Bj8wfKrU6gr5B45il4yvc9omlGE5p5Ul4 DZgvJpVeHn9kG8KRD1hgeEFMLeq5OdzqAIUgxr74dspPG3kUkMICytgzw6AHAWIMRRE9 +53Q== X-Gm-Message-State: AOJu0YwEsV88zgoHAiO8b7/Q656a+OyqfHC2Y/Xq0LBhZjhCXWsV+4Ws yDkvJeIoS9gfcHsctwl/OeRN1QVnjs6nhKPr8OuPcL37E1n8Irasjw8jSclA X-Google-Smtp-Source: AGHT+IERPbolraPA8qYri/jy+l6QClBvJ4r8xFr1tN5lD09eBAUsnWUOXvfdEC/EtPeVgQzL+6FBfw== X-Received: by 2002:a05:6a00:812:b0:6e2:9ff2:19b1 with SMTP id m18-20020a056a00081200b006e29ff219b1mr4952788pfk.13.1709362475586; Fri, 01 Mar 2024 22:54:35 -0800 (PST) Received: from Thaum. (110-175-172-107.tpgi.com.au. [110.175.172.107]) by smtp.gmail.com with ESMTPSA id m7-20020a62f207000000b006e580678dfbsm3859867pfh.193.2024.03.01.22.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 22:54:35 -0800 (PST) Message-ID: <65e2cd2b.620a0220.3d4c1.2206@mx.google.com> X-Google-Original-Message-ID: Date: Sat, 2 Mar 2024 17:54:30 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++: Don't set DECL_CONTEXT to nested template-template parameters [PR98881] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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, OK for trunk? -- >8 -- When streaming in a nested template-template parameter as in the attached testcase, we end up reaching the containing template-template parameter in 'tpl_parms_fini'. We should not set the DECL_CONTEXT to this (nested) template-template parameter, as it should already be the struct that the outer template-template parameter is declared on. PR c++/98881 gcc/cp/ChangeLog: * module.cc (trees_out::tpl_parms_fini): Clarify logic purely for checking purposes. Don't consider a template template parameter as the owning template. (trees_in::tpl_parms_fini): Don't consider a template template parameter as the owning template. gcc/testsuite/ChangeLog: * g++.dg/modules/tpl-tpl-parm-3_a.H: New test. * g++.dg/modules/tpl-tpl-parm-3_b.C: New test. Signed-off-by: Nathaniel Shead Signed-off-by: Nathaniel Shead Reviewed-by: Patrick Palka Reviewed-by: Jason Merrill Signed-off-by: Nathaniel Shead Reviewed-by: Patrick Palka Reviewed-by: Jason Merrill --- gcc/cp/module.cc | 17 ++++++++++++----- gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_a.H | 11 +++++++++++ gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_b.C | 13 +++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_a.H create mode 100644 gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 67f132d28d7..5663d01ed9c 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -10126,10 +10126,14 @@ trees_out::tpl_parms_fini (tree tmpl, unsigned tpl_levels) tree dflt = TREE_PURPOSE (parm); tree_node (dflt); - if (streaming_p ()) + if (CHECKING_P && streaming_p ()) { + /* Sanity check that the DECL_CONTEXT we'll infer when + streaming in is correct. */ tree decl = TREE_VALUE (parm); - if (TREE_CODE (decl) == TEMPLATE_DECL) + if (TREE_CODE (decl) == TEMPLATE_DECL + /* A template template parm is not the owning template. */ + && !DECL_TEMPLATE_TEMPLATE_PARM_P (tmpl)) { tree ctx = DECL_CONTEXT (decl); tree inner = DECL_TEMPLATE_RESULT (decl); @@ -10164,8 +10168,13 @@ trees_in::tpl_parms_fini (tree tmpl, unsigned tpl_levels) return false; TREE_PURPOSE (parm) = dflt; + /* Original template template parms have a context + of their owning template. Reduced ones do not. + But if TMPL is itself a template template parm + then it cannot be the owning template. */ tree decl = TREE_VALUE (parm); - if (TREE_CODE (decl) == TEMPLATE_DECL) + if (TREE_CODE (decl) == TEMPLATE_DECL + && !DECL_TEMPLATE_TEMPLATE_PARM_P (tmpl)) { tree inner = DECL_TEMPLATE_RESULT (decl); tree tpi = (TREE_CODE (inner) == TYPE_DECL @@ -10173,8 +10182,6 @@ trees_in::tpl_parms_fini (tree tmpl, unsigned tpl_levels) : DECL_INITIAL (inner)); bool original = (TEMPLATE_PARM_LEVEL (tpi) == TEMPLATE_PARM_ORIG_LEVEL (tpi)); - /* Original template template parms have a context - of their owning template. Reduced ones do not. */ if (original) DECL_CONTEXT (decl) = tmpl; } diff --git a/gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_a.H b/gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_a.H new file mode 100644 index 00000000000..21bbc054fa3 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_a.H @@ -0,0 +1,11 @@ +// PR c++/98881 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +template struct X {}; + +template