From 4912defbcc3cc0d3a3af9673e413d45731c94da2 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 15 Feb 2018 13:15:32 -0500 Subject: [PATCH] PR c++/84368 - wrong error with local variable in variadic lambda. * pt.c (tsubst_pack_expansion): Fix handling of non-packs in local_specializations. From-SVN: r257699 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 5 +++-- .../g++.dg/cpp1y/lambda-generic-variadic14.C | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f7fd4e36278..5ecc8ab2672 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-15 Jason Merrill + + PR c++/84368 - wrong error with local variable in variadic lambda. + * pt.c (tsubst_pack_expansion): Fix handling of non-packs in + local_specializations. + 2018-02-15 Paolo Carlini PR c++/84330 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); +} -- 2.30.2