c++: ICE with unexpanded pack in do-while [PR99063]
authorMarek Polacek <polacek@redhat.com>
Thu, 11 Feb 2021 03:51:30 +0000 (22:51 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 11 Feb 2021 16:12:49 +0000 (11:12 -0500)
Here an unexpanded parameter pack snuck into prep_operand which doesn't
expect to see an operand without a type, and since r247842
NONTYPE_ARGUMENT_PACK doesn't have a type anymore.

This only happens with the do-while loop whose condition may not
contain a declaration so we never called finish_cond which checks
for unexpanded parameter packs.  So use check_for_bare_parameter_packs
to remedy that.

gcc/cp/ChangeLog:

PR c++/99063
* semantics.c (finish_do_stmt): Check for unexpanded parameter packs.

gcc/testsuite/ChangeLog:

PR c++/99063
* g++.dg/cpp0x/variadic-crash6.C: New test.

gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/variadic-crash6.C [new file with mode: 0644]

index 73834467fcaef48026a6fa6b4e8117591aabc9d0..30dd206c89926e1eec76b3c68b94396ca89efb74 100644 (file)
@@ -1028,6 +1028,11 @@ finish_do_stmt (tree cond, tree do_stmt, bool ivdep, unsigned short unroll)
 {
   cond = maybe_convert_cond (cond);
   end_maybe_infinite_loop (cond);
+  /* Unlike other iteration statements, the condition may not contain
+     a declaration, so we don't call finish_cond which checks for
+     unexpanded parameter packs.  */
+  if (check_for_bare_parameter_packs (cond))
+    cond = error_mark_node;
   if (ivdep && cond != error_mark_node)
     cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
                   build_int_cst (integer_type_node, annot_expr_ivdep_kind),
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-crash6.C b/gcc/testsuite/g++.dg/cpp0x/variadic-crash6.C
new file mode 100644 (file)
index 0000000..88009b7
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/99063
+// { dg-do compile { target c++11 } }
+
+template <typename... T>
+void f (T... n)
+{
+  do
+    {
+    }
+  while (--n); // { dg-error "parameter packs not expanded with '...'" }
+}
+
+void g ()
+{
+  f(3);
+}