Avoid ICE on unsupported use of __integer_pack.
authorJason Merrill <jason@redhat.com>
Sat, 19 May 2018 22:57:53 +0000 (18:57 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 19 May 2018 22:57:53 +0000 (18:57 -0400)
* pt.c (tsubst_pack_expansion): Sorry rather than abort
on __integer_pack as subexpression of pattern.

From-SVN: r260404

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/ext/integer-pack4.C [new file with mode: 0644]

index e4fcffca05bc271f04e9acf81a7aef2fd16ff302..92039fa8e9a837a7ec45af9e9f582d49b286f0c2 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-19  Jason Merrill  <jason@redhat.com>
+
+       * pt.c (tsubst_pack_expansion): Sorry rather than abort
+       on __integer_pack as subexpression of pattern.
+
 2018-05-18  Jason Merrill  <jason@redhat.com>
 
        PR c++/58407 - deprecated implicit copy ops.
index 1e4204043bb6e1c9a1cc8ca412ffeb3ca73d0565..81de633b1eeba4e263397c4dea777cf96e46f44b 100644 (file)
@@ -12067,8 +12067,13 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
        }
       else if (builtin_pack_call_p (parm_pack))
        {
-         /* ??? Support use in other patterns.  */
-         gcc_assert (parm_pack == pattern);
+         if (parm_pack != pattern)
+           {
+             if (complain & tf_error)
+               sorry ("%qE is not the entire pattern of the pack expansion",
+                      parm_pack);
+             return error_mark_node;
+           }
          return expand_builtin_pack_call (parm_pack, args,
                                           complain, in_decl);
        }
diff --git a/gcc/testsuite/g++.dg/ext/integer-pack4.C b/gcc/testsuite/g++.dg/ext/integer-pack4.C
new file mode 100644 (file)
index 0000000..6e5125b
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-additional-options -std=c++17 }
+
+template<int ... Ns> int f() { return (Ns + ...); }
+template<int N> int g() {
+  return f<__integer_pack(N)...>(); // Fine.
+}
+template<int N> int h() {
+  return f<(2*__integer_pack(N))...>(); // { dg-bogus "sorry" "" { xfail *-*-* } }
+}
+int main() { return g<3>()+h<3>(); }