]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix for printing std::meta::info [PR124489]
authorMarek Polacek <polacek@redhat.com>
Fri, 13 Mar 2026 17:00:46 +0000 (13:00 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 16 Mar 2026 21:59:54 +0000 (17:59 -0400)
When printing the diagnostics in this test, we're saying
"constexprstd::meta::info dm" which misses a space.  We
should use pp_cxx_ws_string which does pp_c_maybe_whitespace
when printing "std::meta::info".

PR c++/124489

gcc/cp/ChangeLog:

* error.cc (dump_type) <case NULLPTR_TYPE>: Use pp_cxx_ws_string
instead of pp_string.
<case META_TYPE>: Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/diag6.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/error.cc
gcc/testsuite/g++.dg/reflect/diag6.C [new file with mode: 0644]

index 25e438c1784da9ac6634c81b3ddfee3d552e75e2..f198a1fe06561246bbad3c7db07967c93f46fd3a 100644 (file)
@@ -875,11 +875,11 @@ dump_type (cxx_pretty_printer *pp, tree t, int flags)
       break;
 
     case NULLPTR_TYPE:
-      pp_string (pp, "std::nullptr_t");
+      pp_cxx_ws_string (pp, "std::nullptr_t");
       break;
 
     case META_TYPE:
-      pp_string (pp, "std::meta::info");
+      pp_cxx_ws_string (pp, "std::meta::info");
       break;
 
     case SPLICE_SCOPE:
diff --git a/gcc/testsuite/g++.dg/reflect/diag6.C b/gcc/testsuite/g++.dg/reflect/diag6.C
new file mode 100644 (file)
index 0000000..61caa08
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/124489
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+void
+g ()
+{
+  constexpr decltype(^^::) dm = ^^int; // { dg-message ".constexpr std::meta::info dm. previously declared here" }
+  constexpr decltype(^^::) dm = ^^int; // { dg-error "redeclaration of .constexpr std::meta::info dm." }
+}