diff mbox series

C++ PATCH for c++/82331, ICE with variadic specialization of auto template parm

Message ID CADzB+2m3=JPo+GXP1irAEaVvdzaGBxwNWZQ40voBQwsPvGY-3w@mail.gmail.com
State New
Headers show
Series C++ PATCH for c++/82331, ICE with variadic specialization of auto template parm | expand

Commit Message

Jason Merrill Dec. 5, 2017, 6:05 p.m. UTC
The problem here is that deduction of F tries to substitute into the
type of F, but we haven't deduced R or A yet, so we can't do anything.
tsubst_pack_expansion knows how to handle this, but only expects to
see it within a template.  In general, substitution in the middle of
deduction needs to be treated as happening in template context.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 353564f5e2bcc9108fa3f2ef770d5b46a3be76d0
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Dec 5 12:41:13 2017 -0500

            PR c++/82331 - ICE with variadic partial specialization of auto
    
            * pt.c (unify) [TEMPLATE_PARM_INDEX]: Set processing_template_decl
            around call to tsubst.
diff mbox series

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 500ac0c64fe..685f34a735d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20942,7 +20942,9 @@  unify (tree tparms, tree targs, tree parm, tree arg, int strict,
 	 template-parameter exactly, except that a template-argument
 	 deduced from an array bound may be of any integral type.
 	 The non-type parameter might use already deduced type parameters.  */
+      ++processing_template_decl;
       tparm = tsubst (TREE_TYPE (parm), targs, 0, NULL_TREE);
+      --processing_template_decl;
       if (tree a = type_uses_auto (tparm))
 	{
 	  tparm = do_auto_deduction (tparm, arg, a, complain, adc_unify);
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto13.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto13.C
new file mode 100644
index 00000000000..2152cef811e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto13.C
@@ -0,0 +1,18 @@ 
+// PR c++/82331
+// { dg-options -std=c++17 }
+
+template <auto>
+class X;
+
+template <typename R, typename... A, R (*F) (A...)>
+class X<F> {
+public:
+    static R call (A... args)
+    {
+        return (*F)(args...);
+    }
+};
+
+int func (int a, int b) { return a + b; }
+
+int test () { return X<&func>::call(1, 2); }