On 2/9/26 6:45 AM, Jakub Jelinek wrote:
On Sun, Feb 08, 2026 at 06:52:26AM +0100, Jakub Jelinek wrote:
But sure, I can move the build_self_reference (); call to right
after TYPE_BEING_DEFINED (type) = 1; and in that case change
tree fields = NULL_TREE; to tree fields = TYPE_FIELDS (type);
too if you prefer. And in that case maybe also remove the
gcc_assert (!TYPE_FIELDS (type)).
Though, it clearly is cheaper to do it first when TYPE_FIELDS
is NULL and so chainon doesn't have to walk all the FIELD_DECLs
in the list.
So I'm testing:
OK.
2026-02-08 Jakub Jelinek <[email protected]>
PR c++/123984
* reflect.cc (eval_define_aggregate): Set TYPE_BEING_DEFINED on type
after pushclass, call build_self_reference, remove assertion that
TYPE_FIELDS (type) is NULL and instead set fields to
TYPE_FIELDS (type).
* g++.dg/reflect/define_aggregate6.C: New test.
--- gcc/cp/reflect.cc.jj 2026-02-06 11:18:47.088640019 +0100
+++ gcc/cp/reflect.cc 2026-02-08 21:08:01.359261427 +0100
@@ -6080,8 +6080,9 @@ eval_define_aggregate (location_t loc, c
if (!TYPE_BINFO (type))
xref_basetypes (type, NULL_TREE);
pushclass (type);
- gcc_assert (!TYPE_FIELDS (type));
- tree fields = NULL_TREE;
+ TYPE_BEING_DEFINED (type) = 1;
+ build_self_reference ();
+ tree fields = TYPE_FIELDS (type);
for (int i = 0; i < TREE_VEC_LENGTH (rvec); ++i)
{
tree ra = TREE_VEC_ELT (rvec, i);
--- gcc/testsuite/g++.dg/reflect/define_aggregate6.C.jj 2026-02-05
17:42:07.498427315 +0100
+++ gcc/testsuite/g++.dg/reflect/define_aggregate6.C 2026-02-05
17:41:55.461630714 +0100
@@ -0,0 +1,22 @@
+// PR c++/123984
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+struct A;
+consteval
+{
+ define_aggregate (^^A, { data_member_spec (^^int, {.name{"_"}}) });
+}
+
+struct B : A {};
+
+constexpr int
+get (B &&d)
+{
+ constexpr auto ctx = std::meta::access_context::unchecked ();
+ return static_cast <A*> (&d)->[: nonstatic_data_members_of (^^A, ctx)[0] :];
+}
+
+static_assert (get (B { 123 }) == 123);
Jakub