I started adding non-pack locals to PACK_EXPANSION_EXTRA_ARGS, but was still only looking up specializations for the packs...
Tested x86_64-pc-linux-gnu, applying to trunk.
commit c61b45ad2d0886dc53dde7ba95382efa29288b2d Author: Jason Merrill <ja...@redhat.com> Date: Thu Feb 15 12:56:47 2018 -0500 PR c++/84368 - wrong error with local variable in variadic lambda. * pt.c (tsubst_pack_expansion): Fix handling of non-packs in local_specializations. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 3ac7adba00c..cd1aed8d677 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11521,8 +11521,9 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, context. */ tree gen = TREE_PURPOSE (elt); tree inst = TREE_VALUE (elt); - if (DECL_PACK_P (inst)) - inst = retrieve_local_specialization (inst); + if (DECL_P (inst)) + if (tree local = retrieve_local_specialization (inst)) + inst = local; /* else inst is already a full instantiation of the pack. */ register_local_specialization (inst, gen); } diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic14.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic14.C new file mode 100644 index 00000000000..76567966293 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic14.C @@ -0,0 +1,17 @@ +// PR c++/84368 +// { dg-do compile { target c++14 } } + +template < typename ... T > +void sink(T ...){} + +template < typename ... T > +void foo(T ... v){ + [](auto ... v){ + auto bar = [](auto, auto){ return 0; }; + sink(bar(v, T{}) ...); + }(v ...); +} + +int main(){ + foo(0); +}