C++ PATCH for c++/84015, ICE with class deduction and auto template parm

Message ID CADzB+2=dvGq5P79_oQTjAQhx2hrfeWHYu8P5-zQ_Fu9vNBs+Jw@mail.gmail.com
State New
Headers show
  • C++ PATCH for c++/84015, ICE with class deduction and auto template parm
Related show

Commit Message

Jason Merrill Feb. 26, 2018, 5:02 a.m.
While rewriting the template parameters of a member template
constructor to generate the corresponding deduction guide, we tsubst
the parms twice.  In this bug, on the first pass we ended up lowering
the level of the 'auto' TEMPLATE_TYPE_PARM to 1, so the second pass
blows up.  This is very similar to the situation that I already
introduced tf_partial for, so let's use it here as well.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 2b7c1f2a66551ce9462c82d119820b524a83b28e
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Feb 25 21:50:15 2018 -0500

            PR c++/84015 - ICE with class deduction and auto template parm.
            * pt.c (rewrite_template_parm): Use tf_partial in first tsubst.


diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 85d1adbbe3c..9cf96e9fbe4 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -25596,7 +25596,7 @@  rewrite_template_parm (tree olddecl, unsigned index, unsigned level,
 	  // Substitute ttargs into ttparms to fix references to
 	  // other template parameters.
 	  ttparms = tsubst_template_parms_level (ttparms, ttargs,
-						 complain);
+						 complain|tf_partial);
 	  // Now substitute again with args based on tparms, to reduce
 	  // the level of the ttparms.
 	  ttargs = current_template_args ();
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction49.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction49.C
new file mode 100644
index 00000000000..086f12ad3c6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction49.C
@@ -0,0 +1,15 @@ 
+// PR c++/84015
+// { dg-additional-options -std=c++17 }
+template <int I>
+struct A { };
+template <int I>
+struct B
+  template<template<auto>class T>
+  B(T<I>);
+A<42> a;
+B b (a);