]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Improve REFLECT_EXPR printing [PR125007]
authorJakub Jelinek <jakub@redhat.com>
Thu, 7 May 2026 15:31:09 +0000 (17:31 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 7 May 2026 15:31:09 +0000 (17:31 +0200)
commite8aa21caed8a3c8b4b27d224a04296f008bcf3da
tree932f3f1ad6f7fda7138d20e87ed0f80547d1971a
parent75244f0e73b51d8268052b8d18935ca774f00060
c++: Improve REFLECT_EXPR printing [PR125007]

The following patch fixes REFLECT_EXPR printing.  Currently it prints everything
as ^^ followed by dumping the decl/type/expr handle of the REFLECT_EXPR_HANDLE
except the weird printing of data member specifications.
E.g. annotations are printed as ^^ and dump_expr on the REFLECT_EXPR_HANDLE,
which is a TREE_LIST so it prints the TREE_VALUE of TREE_VALUE of that in
the end and prints e.g. reflection of [[=1]] as ^^1.
The following patch prints reflections of annotations as ^^[[=1]] which is
also not valid C++ syntax, but because the IL doesn't store the decl/type
etc. in whose DECL_ATTRIBUTES/TYPE_ATTRIBUTES it appears, I'm afraid we
can't do much better (like print annotations_of(^^something)[N]).
For REFLECT_BASE/REFLECT_PARM/REFLECT_DATA_MEMBER_SPEC/REFLECT_VALUE/REFLECT_OBJECT,
it attempts to use the C++ valid syntax, so prints
bases_of(^^type,std::meta::access_context::unchecked())[N] {aka base_type}
parameters_of(^^decl)[N] {aka param_name}
data_member_spec(^^type,{.name="foo"})
std::meta::reflect_constant(X)
std::meta::reflect_object(X)
etc.

2026-05-07  Jakub Jelinek  <jakub@redhat.com>

PR c++/125007
* cp-tree.h (maybe_update_function_parm): Declare.
* reflect.cc (maybe_update_function_parm): No longer static.
* error.cc (dump_expr) <case REFLECT_EXPR>: Improve printing
of various reflections.

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

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