On Fri, Feb 06, 2026 at 10:38:33AM +0100, Jakub Jelinek wrote:
> Hi!
> 
> We weren't adding the DECL_SELF_REFERENCE_P TYPE_DECL to TYPE_FIELDS of
> eval_define_aggregate created aggregates, which resulted in ICE in
> accessible_base_p which relies on DECL_SELF_REFERENCE_P TYPE_DECL to be
> present in base classes of other classes.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

Looks ok.
 
> 2026-02-05  Jakub Jelinek  <[email protected]>
> 
>       PR c++/123984
>       * reflect.cc (eval_define_aggregate): Set TYPE_BEING_DEFINED on type
>       after pushclass and call build_self_reference before finish_struct.
> 
>       * g++.dg/reflect/define_aggregate6.C: New test.
> 
> --- gcc/cp/reflect.cc.jj      2026-02-05 15:19:21.963084934 +0100
> +++ gcc/cp/reflect.cc 2026-02-05 17:40:03.901515578 +0100
> @@ -6081,6 +6081,7 @@ eval_define_aggregate (location_t loc, c
>      xref_basetypes (type, NULL_TREE);
>    pushclass (type);
>    gcc_assert (!TYPE_FIELDS (type));
> +  TYPE_BEING_DEFINED (type) = 1;
>    tree fields = NULL_TREE;
>    for (int i = 0; i < TREE_VEC_LENGTH (rvec); ++i)
>      {
> @@ -6121,6 +6122,7 @@ eval_define_aggregate (location_t loc, c
>        fields = f;
>      }
>    TYPE_FIELDS (type) = fields;
> +  build_self_reference ();
>    finish_struct (type, NULL_TREE);
>    return get_reflection_raw (loc, orig_type);
>  }
> --- 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
> 

Marek

Reply via email to