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.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

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                           |  5 +++++
 gcc/testsuite/g++.dg/cpp0x/variadic-crash6.C | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/variadic-crash6.C

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 73834467fca..30dd206c899 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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
index 00000000000..88009b765c2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic-crash6.C
@@ -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);
+}

base-commit: 27a804bc62805aedb1b097a00eb2c0059244680a
-- 
2.29.2

Reply via email to