From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7948) id AB0D43858D35; Thu, 7 Mar 2024 11:00:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB0D43858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709809202; bh=RVwjbaQdzON+0NuLfHjD1DoaO6HK4JR5iCVihBH+Urw=; h=From:To:Subject:Date:From; b=v71YcxNemaqDuIvkhN75RuAmpbbXLRhUkhyG2SGC9BXtrWTJYEskiMtExYdUZoCyz JCl9MtTUykbGZj43FPqpSmiLiMaKuGmvjZzyOkw1V+RwTTkWoxijMRVW1ypmOQYrlJ dhg0Ff1h9xVSQZOyWeKoRQmBH+f20aoofILc0MOY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Nathaniel Shead To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9356] c++: Stream DECL_CONTEXT for template template parms [PR98881] X-Act-Checkin: gcc X-Git-Author: Nathaniel Shead X-Git-Refname: refs/heads/master X-Git-Oldrev: b209d905f5ce1fa9d76ce634fd54245ff340960b X-Git-Newrev: 77772f8a3da8ea30066d2201f8148714a8e89da5 Message-Id: <20240307110002.AB0D43858D35@sourceware.org> Date: Thu, 7 Mar 2024 11:00:02 +0000 (GMT) List-Id: https://gcc.gnu.org/g:77772f8a3da8ea30066d2201f8148714a8e89da5 commit r14-9356-g77772f8a3da8ea30066d2201f8148714a8e89da5 Author: Nathaniel Shead Date: Tue Mar 5 15:17:09 2024 +1100 c++: Stream DECL_CONTEXT for template template parms [PR98881] 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. The precise logic for what DECL_CONTEXT should be for a template template parameter in various situations seems rather obscure. Rather than trying to determine the assumptions that need to hold, it seems simpler to just always re-stream the DECL_CONTEXT as needed for now. PR c++/98881 gcc/cp/ChangeLog: * module.cc (trees_out::tpl_parms_fini): Stream out DECL_CONTEXT for template template parameters. (trees_in::tpl_parms_fini): Read it. gcc/testsuite/ChangeLog: * g++.dg/modules/tpl-tpl-parm-3.h: New test. * g++.dg/modules/tpl-tpl-parm-3_a.H: New test. * g++.dg/modules/tpl-tpl-parm-3_b.C: New test. * g++.dg/modules/tpl-tpl-parm-3_c.C: New test. Signed-off-by: Nathaniel Shead Reviewed-by: Patrick Palka Reviewed-by: Jason Merrill Diff: --- gcc/cp/module.cc | 41 ++++++------------------- gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3.h | 12 ++++++++ gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_a.H | 5 +++ gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_b.C | 5 +++ gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3_c.C | 15 +++++++++ 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 80b63a70a62..f7e8b357fc2 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -10126,23 +10126,12 @@ trees_out::tpl_parms_fini (tree tmpl, unsigned tpl_levels) tree dflt = TREE_PURPOSE (parm); tree_node (dflt); - if (streaming_p ()) - { - tree decl = TREE_VALUE (parm); - if (TREE_CODE (decl) == TEMPLATE_DECL) - { - tree ctx = DECL_CONTEXT (decl); - tree inner = DECL_TEMPLATE_RESULT (decl); - tree tpi = (TREE_CODE (inner) == TYPE_DECL - ? TEMPLATE_TYPE_PARM_INDEX (TREE_TYPE (decl)) - : 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. */ - gcc_checking_assert (original ? ctx == tmpl : !ctx); - } - } + /* Template template parameters need a context of their owning + template. This is quite tricky to infer correctly on stream-in + (see PR c++/98881) so we'll just provide it directly. */ + tree decl = TREE_VALUE (parm); + if (TREE_CODE (decl) == TEMPLATE_DECL) + tree_node (DECL_CONTEXT (decl)); } } } @@ -10160,24 +10149,14 @@ trees_in::tpl_parms_fini (tree tmpl, unsigned tpl_levels) { tree parm = TREE_VEC_ELT (vec, ix); tree dflt = tree_node (); - if (get_overrun ()) - return false; TREE_PURPOSE (parm) = dflt; tree decl = TREE_VALUE (parm); if (TREE_CODE (decl) == TEMPLATE_DECL) - { - tree inner = DECL_TEMPLATE_RESULT (decl); - tree tpi = (TREE_CODE (inner) == TYPE_DECL - ? TEMPLATE_TYPE_PARM_INDEX (TREE_TYPE (decl)) - : 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; - } + DECL_CONTEXT (decl) = tree_node (); + + if (get_overrun ()) + return false; } } return true; diff --git a/gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3.h b/gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3.h new file mode 100644 index 00000000000..b0dcf353c23 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/tpl-tpl-parm-3.h @@ -0,0 +1,12 @@ +// PR c++/98881 + +template struct X {}; + +template