C++ PATCH for c++/84036, ICE with variadic capture

Jason Merrill jason@redhat.com
Fri Jan 26 17:24:00 GMT 2018


My recent patch for 82249 caused a substitution here to return a
TREE_VEC rather than an EXPR_PACK_EXPANSION; fixed by pulling out the
expansion in that case.

Tested x86_64-pc-linux-gnu, applying to trunk.
-------------- next part --------------
commit 577e646e8472e6bc226168fb96d0884663b0c2cd
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jan 26 10:51:17 2018 -0500

            PR c++/84036 - ICE with variadic capture.
    
            * pt.c (tsubst_pack_expansion): When optimizing a simple
            substitution, pull a single pack expansion out of its pack.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index de8ad94200a..6c5d06b9ebb 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11575,6 +11575,12 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
       && TREE_PURPOSE (packs) == pattern)
     {
       tree args = ARGUMENT_PACK_ARGS (TREE_VALUE (packs));
+
+      /* If the argument pack is a single pack expansion, pull it out.  */
+      if (TREE_VEC_LENGTH (args) == 1
+	  && pack_expansion_args_count (args))
+	return TREE_VEC_ELT (args, 0);
+
       /* Types need no adjustment, nor does sizeof..., and if we still have
 	 some pack expansion args we won't do anything yet.  */
       if (TREE_CODE (t) == TYPE_PACK_EXPANSION
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic8.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic8.C
new file mode 100644
index 00000000000..7740d660de2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic8.C
@@ -0,0 +1,13 @@
+// PR c++/84036
+// { dg-do compile { target c++14 } }
+
+template < typename T >
+auto f(T){
+    [](auto ... i){
+        [i ...]{};
+    };
+}
+
+int main(){
+    f(0);
+}


More information about the Gcc-patches mailing list