https://gcc.gnu.org/g:91733c095ee714c0b384153754c6327d5506cd19

commit r15-6313-g91733c095ee714c0b384153754c6327d5506cd19
Author: Marek Polacek <pola...@redhat.com>
Date:   Tue Dec 17 13:44:22 2024 -0500

    c++: print NONTYPE_ARGUMENT_PACK [PR118073]
    
    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.

Diff:
---
 gcc/cp/error.cc                             | 15 +++++++++++++++
 gcc/testsuite/g++.dg/diagnostic/arg-pack1.C | 10 ++++++++++
 2 files changed, 25 insertions(+)

diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 4736f4875eaf..8c0644fba7ea 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -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
index 000000000000..643fc7f665e2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/arg-pack1.C
@@ -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} }
+}

Reply via email to