PR c++/84368 - wrong error with local variable in variadic lambda.
authorJason Merrill <jason@redhat.com>
Thu, 15 Feb 2018 18:15:32 +0000 (13:15 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 15 Feb 2018 18:15:32 +0000 (13:15 -0500)
* pt.c (tsubst_pack_expansion): Fix handling of non-packs in
local_specializations.

From-SVN: r257699

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic14.C [new file with mode: 0644]

index f7fd4e36278cb05f1062bcbff4b73fdcbbd2a11f..5ecc8ab2672bc46a980c0c9b9fbb7e1341f33e04 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-15  Jason Merrill  <jason@redhat.com>
+
+       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  <paolo.carlini@oracle.com>
 
        PR c++/84330
index 3ac7adba00c97e6a4ea1618873dccebb219eb2e0..cd1aed8d677a075071b5d9c52f2dd76f755e0100 100644 (file)
@@ -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 (file)
index 0000000..7656796
--- /dev/null
@@ -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);
+}