diff mbox

C++ PATCH for c++/78282, auto template and pack expansion

Message ID CADzB+2nJiFQBrSG9N1fVHKACvtFvPv70aOwBCWRDq=_Pc5cAeA@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill Feb. 20, 2017, 6:02 a.m. UTC
When looking for parameter packs mentioned within an expression, we
were wrongly walking into the type of a TEMPLATE_DECL mentioned in the
expression.  We're only interested in packs in the type of a template
template-parameter, not other kinds of template.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 1835d19d99d5e89155c566d6305c878ca0c75678
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Feb 19 16:08:29 2017 -0800

            PR c++/78282 - auto template and pack expansion
    
            * pt.c (find_parameter_packs_r): Don't walk into the type of
            templates other than template template-parameters.
diff mbox

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 0a9f5d5..2cac24f 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3576,8 +3576,12 @@  find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data)
       *walk_subtrees = 0;
       return NULL_TREE;
 
-    case CONSTRUCTOR:
     case TEMPLATE_DECL:
+      if (!DECL_TEMPLATE_TEMPLATE_PARM_P (t))
+	return NULL_TREE;
+      gcc_fallthrough();
+
+    case CONSTRUCTOR:
       cp_walk_tree (&TREE_TYPE (t),
 		    &find_parameter_packs_r, ppd, ppd->visited);
       return NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn36.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn36.C
new file mode 100644
index 0000000..f89c092
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn36.C
@@ -0,0 +1,26 @@ 
+// PR c++/78282
+// { dg-do compile { target c++14 } }
+
+struct null_node
+{
+  null_node(const null_node&);
+};
+
+extern null_node null;
+
+template <typename T>
+auto get() { return null; }
+
+template <typename... Ts>
+struct inheritor: Ts...
+{
+  inheritor(const inheritor& outer)
+    : Ts(get<Ts...>())...
+    { }
+};
+
+void test()
+{
+  extern inheritor<null_node> example;
+  inheritor<null_node> result(example);
+}