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.129.124]) by sourceware.org (Postfix) with ESMTPS id 87AFE3858C66 for ; Tue, 5 Mar 2024 00:14:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87AFE3858C66 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 87AFE3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709597700; cv=none; b=q74xhT1wF3AbBV7l3WRlRn5blpyWOETAS2EMmhG0ocUm5kMW1/ceEgQo4EQ/cnCU8rIL9BrNVrjZQRKPuMd3dsVSc5cD+/eW18Kpth8rmUz9Rmj9pHd63x/REaVAgJvNqDpE4zgDRHeGmvxj8X086tjYHl8EMOR8/7r4POqs71Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709597700; c=relaxed/simple; bh=kW2xMS5QsR69kiBf5XbjlaNf0kMwcJB18pcNxdPjGaE=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=tMbueQ+WOK7Ii3QGRE3qUosvApiP1xX2MikKOErQQfZphoOW3jMHLBXgbWow7p5NcTc/7W7ZqaKd+UCTD6yvp+XjGun8Uib61aDvLuQC/EmG5c8SGT3jEjE74+JDvPvZPszWaeSAObuSaNNvcqvVNFo+RWHKmokP1EhL/4DZimA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709597698; 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=A6bGVBH/iH7WCi29tt1JdV9JS4qn0iboMY3NyJepHuI=; b=bc23ae0NIWhS4iTVj1VbvaUSzSSFLVwReMsrSqu7fhv6rU+0M2XpFHDuzvwrG8TDDTHy5G PoK3rMUwnunudnRaqR5KmEvGq2NRcDVxAY6I+eGDiVrV/vF8aQvoZJCLczA3StJOp36UCs mIkr1upE40Nb476qw7LXda4FGIC37yY= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-HC_cV0whN0KKYYNN4phQ6g-1; Mon, 04 Mar 2024 19:14:56 -0500 X-MC-Unique: HC_cV0whN0KKYYNN4phQ6g-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-78823dda5c2so178774485a.1 for ; Mon, 04 Mar 2024 16:14:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709597696; x=1710202496; 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=A6bGVBH/iH7WCi29tt1JdV9JS4qn0iboMY3NyJepHuI=; b=PPV4Gt9J9OgG9b2IVG4ay9a/v2BDdQVqsU8zufZU6m9dckCEYWq04E9DFfEiXHg2G4 knfNl6i6UvARuuSpFod5FGe51rUcECrYgfSOp4OecKy+bp2RjBS6O+SfiL6jTk4OIBsi 49cSn9vTdEaHreP5nxoTGqZjd1XckZYf3+CiE2qetYsofe6aTVQWTXAFOhgjLKZKGhJJ rpU9rjeFyb1Q4d3XEtlL+wJAZ6B87fXURQGsChpvXU0g6p4IV/vDD63k4Swrjb9a1pmG i3QeC7FXmEG0vygYFf6lcuSx+NHKb7nIqdVSgHUnFhcBiUDkUbosmWJc8/zpzKFXOc94 rdAg== X-Gm-Message-State: AOJu0Yxu9rP+sd5Lz8AwNVHma8m9E+2/eE5fvAU63QSJnTeCTax+c69q +rOZEkn3GiGtG2R+LXrm5mIEhfjuCiWYS/wAd44u5vjbi3cFqxZP5ORFX+dm8813JMqXMeVK2Ox zaWymFK0mR4qvnVhQiLYVYAOeBa7SPerHAmtYvzl0nweDuVfcEIRidlE= X-Received: by 2002:a05:6214:331:b0:690:4f40:86a2 with SMTP id j17-20020a056214033100b006904f4086a2mr445036qvu.7.1709597696356; Mon, 04 Mar 2024 16:14:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+BBRjIXNpKFRn1c/qmgLPyjggEeZ1Y4+bfqHWorEoymWAMPiZQxAvlwpGF/QguG019BTU4Q== X-Received: by 2002:a05:6214:331:b0:690:4f40:86a2 with SMTP id j17-20020a056214033100b006904f4086a2mr445026qvu.7.1709597696079; Mon, 04 Mar 2024 16:14:56 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id a19-20020a0ce353000000b00690314356a4sm5591794qvm.80.2024.03.04.16.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 16:14:55 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 4 Mar 2024 19:14:54 -0500 (EST) To: Nathaniel Shead cc: gcc-patches@gcc.gnu.org, Jason Merrill , Nathan Sidwell Subject: Re: [PATCH] c++: Don't set DECL_CONTEXT to nested template-template parameters [PR98881] In-Reply-To: <65e2cd2b.620a0220.3d4c1.2206@mx.google.com> Message-ID: References: <65e2cd2b.620a0220.3d4c1.2206@mx.google.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=-12.5 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_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Sat, 2 Mar 2024, Nathaniel Shead wrote: > 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 > --- > 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)) IIUC a TEMPLATE_DECL inside a template parameter list always represents a template template parm, so won't this effectively disable the DECL_CONTEXT setting logic? > { > 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