On 5/6/26 3:08 PM, Marek Polacek wrote:
On Wed, May 06, 2026 at 08:28:05PM +0200, Jakub Jelinek wrote:
On Wed, May 06, 2026 at 02:18:06PM -0400, Jason Merrill wrote:
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -3331,6 +3331,11 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
case REFLECT_EXPR:
{
+ if (null_reflection_p (t))
+ {
+ pp_cxx_ws_string (pp, "std::info{}");
"std::meta::info{}"
Otherwise LGTM.
Yeah, looks good with that fixed.
Thanks, pushing the attached.
From 104eb528c1c53f2e9de7e1c50a6d2840ef4be6fe Mon Sep 17 00:00:00 2001
From: Jason Merrill <[email protected]>
Date: Sat, 9 May 2026 05:15:01 -0400
Subject: [PATCH] c++/reflection: add null_reflection_p
To: [email protected]
I wanted to improve %E of info{}, and it seemed desirable to have a
shorter way to spell this test.
gcc/cp/ChangeLog:
* reflect.cc (null_reflection_p): New.
(splice): Use it.
* error.cc (dump_expr): Use it.
* cp-tree.h (null_reflection_p): Declare.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/pr125007.C: Add info{} test.
---
gcc/cp/cp-tree.h | 1 +
gcc/cp/error.cc | 5 +++++
gcc/cp/reflect.cc | 11 ++++++++++-
gcc/testsuite/g++.dg/reflect/pr125007.C | 3 +++
4 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 06dc5af4955..8a168f509d4 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -9524,6 +9524,7 @@ extern tree process_metafunction (const constexpr_ctx *, tree, tree,
bool *, bool *, tree *);
extern tree get_reflection (location_t, tree, reflect_kind = REFLECT_UNDEF);
extern tree get_null_reflection () ATTRIBUTE_PURE;
+extern bool null_reflection_p (const_tree) ATTRIBUTE_PURE;
extern tree splice (tree);
extern bool check_out_of_consteval_use (tree, bool = true);
extern bool consteval_only_p (tree) ATTRIBUTE_PURE;
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index a22c8ee113e..c2fb6027c52 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -3471,6 +3471,11 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
pp_right_paren (pp);
break;
default:
+ if (null_reflection_p (t))
+ {
+ pp_cxx_ws_string (pp, "std::meta::info{}");
+ break;
+ }
pp_string (pp, "^^");
pp->set_padding (pp_none);
if (DECL_P (h))
diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index ad4c77fab3e..c8148d96726 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -267,6 +267,15 @@ get_null_reflection ()
return null_reflection;
}
+/* True iff T is a null reflection. */
+
+bool
+null_reflection_p (const_tree t)
+{
+ return (t && TREE_CODE (t) == REFLECT_EXPR
+ && REFLECT_EXPR_HANDLE (t) == unknown_type_node);
+}
+
/* Do strip_typedefs on T, but only for types. */
static tree
@@ -8533,7 +8542,7 @@ splice (tree refl)
return error_mark_node;
}
- if (compare_reflections (refl, get_null_reflection ()))
+ if (null_reflection_p (refl))
{
error_at (loc, "cannot splice a null reflection");
return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/reflect/pr125007.C b/gcc/testsuite/g++.dg/reflect/pr125007.C
index 4ac0dfe03cc..0939f940dfd 100644
--- a/gcc/testsuite/g++.dg/reflect/pr125007.C
+++ b/gcc/testsuite/g++.dg/reflect/pr125007.C
@@ -44,3 +44,6 @@ void qux (int x, int y);
static_assert (parameters_of (^^qux)[0] == parameters_of (^^qux)[1]); // { dg-error "static assertion failed" }
// { dg-message "note: the comparison reduces to '\\\(parameters_of\\\(\\\^\\\^qux\\\(int, int\\\)\\\)\\\[0\\\] \\\{aka x\\\} == parameters_of\\\(\\\^\\\^qux\\\(int, int\\\)\\\)\\\[1\\\] \\\{aka y\\\}\\\)'" "" { target *-*-* } .-1 }
+
+static_assert (std::meta::info{} == ^^int); // { dg-error "static assertion failed" }
+// { dg-message {note: the comparison reduces to '\(std::meta::info{} == \^\^int\)} "" { target *-*-* } .-1 }
--
2.54.0