Normally cp_parser_base_clause prevents unexpanded packs, but in a lambda
check_for_bare_parameter_packs allows it.  Then we weren't finding the
pack when scanning the lambda body.

This doesn't fix a valid variant like

  template <class... Ts> void sink (Ts&&...);
  template <class... Ts>
  void f() {
    sink ([] { struct S : Ts { }; }...);
  }
  int main() {
    f<int>();
  }

but that's a much bigger project.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/ChangeLog:

        PR c++/100006
        * pt.c (find_parameter_packs_r) [TAG_DEFN]: Look into bases.

gcc/testsuite/ChangeLog:

        PR c++/100006
        * g++.dg/cpp0x/lambda/lambda-variadic13.C: New test.
---
 gcc/cp/pt.c                                           |  9 +++++++++
 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic13.C | 11 +++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic13.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index daf1b5aeb32..ff98bc13551 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4061,6 +4061,15 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, 
void* data)
       *walk_subtrees = 0;
       return NULL_TREE;
 
+    case TAG_DEFN:
+      /* Local class, need to look through the whole definition.  */
+      t = TREE_TYPE (t);
+      if (CLASS_TYPE_P (t))
+       for (tree bb : BINFO_BASE_BINFOS (TYPE_BINFO (t)))
+         cp_walk_tree (&BINFO_TYPE (bb), &find_parameter_packs_r,
+                       ppd, ppd->visited);
+      return NULL_TREE;
+
     default:
       return NULL_TREE;
     }
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic13.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic13.C
new file mode 100644
index 00000000000..ac4e631ebb5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic13.C
@@ -0,0 +1,11 @@
+// PR c++/100006
+// { dg-do compile { target c++14 } }
+
+template <class... Ts>
+void f() {
+  [] { struct S : Ts { }; };   // { dg-error "not expanded" }
+}
+
+int main() {
+  f<>();
+}

base-commit: a7ce23cec4a4a581b88c226418dc702dcd19bceb
-- 
2.27.0

Reply via email to