]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: print NONTYPE_ARGUMENT_PACK [PR118073]
authorMarek Polacek <polacek@redhat.com>
Tue, 17 Dec 2024 18:44:22 +0000 (13:44 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 17 Dec 2024 19:27:49 +0000 (14:27 -0500)
This PR points out that we're not pretty-printing NONTYPE_ARGUMENT_PACK
so the compiler emits the ugly:

  'nontype_argument_pack' not supported by dump_expr<expression error>>

Fixed thus.  I've wrapped the elements of the pack in { } because that's
what cxx_pretty_printer::expression does.

PR c++/118073

gcc/cp/ChangeLog:

* error.cc (dump_expr) <case NONTYPE_ARGUMENT_PACK>: New case.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/arg-pack1.C: New test.

gcc/cp/error.cc
gcc/testsuite/g++.dg/diagnostic/arg-pack1.C [new file with mode: 0644]

index 4736f4875eaf3a2e169e87d7c4a395a08d1a639d..8c0644fba7ea7fb1c43c10b1c877090dcd83764e 100644 (file)
@@ -3173,6 +3173,21 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
       dump_expr_list (pp, t, flags);
       break;
 
+    case NONTYPE_ARGUMENT_PACK:
+      {
+       tree args = ARGUMENT_PACK_ARGS (t);
+       int len = TREE_VEC_LENGTH (args);
+       pp_cxx_left_brace (pp);
+       for (int i = 0; i < len; ++i)
+         {
+           if (i > 0)
+             pp_separate_with_comma (pp);
+           dump_expr (pp, TREE_VEC_ELT (args, i), flags);
+         }
+       pp_cxx_right_brace (pp);
+       break;
+      }
+
       /*  This list is incomplete, but should suffice for now.
          It is very important that `sorry' does not call
          `report_error_function'.  That could cause an infinite loop.  */
diff --git a/gcc/testsuite/g++.dg/diagnostic/arg-pack1.C b/gcc/testsuite/g++.dg/diagnostic/arg-pack1.C
new file mode 100644 (file)
index 0000000..643fc7f
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/118073
+// { dg-do compile { target c++11 } }
+
+template<int... Ns>
+struct index_sequence {};
+
+void foo()
+{
+    index_sequence<5> bar = index_sequence<1>(); // { dg-error {conversion from 'index_sequence<\{1\}>' to non-scalar type 'index_sequence<\{5\}>' requested} }
+}