public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-7692] c++: passing partially inst tmpl as ttp [PR110566]
@ 2023-08-07 23:27 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2023-08-07 23:27 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2c6e76ff039782401f705cacda60c11f8dfac3b1

commit r13-7692-g2c6e76ff039782401f705cacda60c11f8dfac3b1
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jul 26 17:21:26 2023 -0400

    c++: passing partially inst tmpl as ttp [PR110566]
    
    Since the template arguments 'pargs' we pass to coerce_template_parms from
    coerce_template_template_parms are always a full set, we need to make sure
    we always pass the parameters of the most general template because if the
    template is partially instantiated then the levels won't match up.  In the
    testcase below during said call to coerce_template_parms the parameters are
    {X, Y}, both level 1 rather than 2, and the arguments are {{int}, {N, M}},
    which results in a crash during auto deduction for parameters' types.
    
            PR c++/110566
            PR c++/108179
    
    gcc/cp/ChangeLog:
    
            * pt.cc (coerce_template_template_parms): Simplify by using
            DECL_INNERMOST_TEMPLATE_PARMS and removing redundant asserts.
            Always pass the parameters of the most general template to
            coerce_template_parms.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/template/ttp38.C: New test.
    
    (cherry picked from commit b3adcc60dcf3314f47f5409aecef40607f82b80b)

Diff:
---
 gcc/cp/pt.cc                          | 12 +++++-------
 gcc/testsuite/g++.dg/template/ttp38.C | 12 ++++++++++++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index fd6bb4a2167..8dec93bb0fb 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -8076,12 +8076,10 @@ coerce_template_template_parms (tree parm_tmpl,
   tree parm, arg;
   int variadic_p = 0;
 
-  tree parm_parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (parm_tmpl));
-  tree arg_parms_full = DECL_TEMPLATE_PARMS (arg_tmpl);
-  tree arg_parms = INNERMOST_TEMPLATE_PARMS (arg_parms_full);
-
-  gcc_assert (TREE_CODE (parm_parms) == TREE_VEC);
-  gcc_assert (TREE_CODE (arg_parms) == TREE_VEC);
+  tree parm_parms = DECL_INNERMOST_TEMPLATE_PARMS (parm_tmpl);
+  tree arg_parms = DECL_INNERMOST_TEMPLATE_PARMS (arg_tmpl);
+  tree gen_arg_tmpl = most_general_template (arg_tmpl);
+  tree gen_arg_parms = DECL_INNERMOST_TEMPLATE_PARMS (gen_arg_tmpl);
 
   nparms = TREE_VEC_LENGTH (parm_parms);
   nargs = TREE_VEC_LENGTH (arg_parms);
@@ -8137,7 +8135,7 @@ coerce_template_template_parms (tree parm_tmpl,
 	scope_args = TI_ARGS (tinfo);
       pargs = add_to_template_args (scope_args, pargs);
 
-      pargs = coerce_template_parms (arg_parms, pargs, NULL_TREE, tf_none);
+      pargs = coerce_template_parms (gen_arg_parms, pargs, NULL_TREE, tf_none);
       if (pargs != error_mark_node)
 	{
 	  tree targs = make_tree_vec (nargs);
diff --git a/gcc/testsuite/g++.dg/template/ttp38.C b/gcc/testsuite/g++.dg/template/ttp38.C
new file mode 100644
index 00000000000..4a0c27f42aa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ttp38.C
@@ -0,0 +1,12 @@
+// PR c++/110566
+// { dg-do compile { target c++20 } }
+
+template<template<int N, int M> class>
+struct A;
+
+template<class T>
+struct B {
+  template<auto X, auto Y> struct C;
+};
+
+using type = A<B<int>::C>;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-07 23:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-07 23:27 [gcc r13-7692] c++: passing partially inst tmpl as ttp [PR110566] Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).