Here when asking for the members of "^^Test const" we found nothing.
The reason is that members_of_representable_p checks whether
CP_DECL_CONTEXT != c, but if c is a type, it doesn't look at its
TYPE_MAIN_VARIANT. Fixed as per Jakub's suggestion in the PR.
PR c++/124215
gcc/cp/ChangeLog:
* reflect.cc (class_members_of): Use TYPE_MAIN_VARIANT of R.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/members_of9.C: New test.
Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
tree actx, tree call, bool *non_constant_p,
tree *jump_target, enum metafn_code kind, tree fun)
{
+ r = TYPE_MAIN_VARIANT (r);
if (kind == METAFN_MEMBERS_OF)
{
if (modules_p ())
--- /dev/null
+// PR c++/124215
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+struct Test {
+ int a;
+ char b;
+};
+
+consteval auto number_of_members(std::meta::info ty) -> size_t {
+ return nonstatic_data_members_of(ty, std::meta::access_context::current()).size();
+}
+
+static_assert(number_of_members(^^Test) == 2);
+static_assert(number_of_members(^^Test const) == 2);