https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124991

--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Jakub Jelinek
<[email protected]>:

https://gcc.gnu.org/g:5e375a47bc7bfd8d97318e23c689487ed936041b

commit r16-8909-g5e375a47bc7bfd8d97318e23c689487ed936041b
Author: Jakub Jelinek <[email protected]>
Date:   Thu May 7 08:45:32 2026 +0200

    c++: Reflection vs. CLASSTYPE_TYPEINFO_VAR/ANON_AGGR_TYPE_FIELD sharing
[PR124991]

    typeinfo_var element of lang_type is used for 2 purposes,
    CLASSTYPE_TYPEINFO_VAR and ANON_AGGR_TYPE_FIELD, a VAR_DECL for types
    for which we need typeid etc. and FIELD_DECL for anonymous union/struct
    types inside of classes.
    Without reflection one can't ask for typeid of the anonymous union/struct
    types, so sharing the same tree for both purposes is fine, but with
    reflection we can ICE.

    As anonymous unions are fairly rare and asking about typeid of those will
be
    even rarer, the following patch attempts to fix that without actually
    growing the lang_type struct size by using the same tree for both.  If it
    is NULL_TREE, both CLASSTYPE_TYPEINFO_VAR and ANON_AGGR_TYPE_FIELD
    are NULL, if it is a VAR_DECL, it is the former, if it is a FIELD_DECL,
    it is the latter, in the really rare case we need both it is turned
    into a TREE_LIST where TREE_VALUE is CLASSTYPE_TYPEINFO_VAR and
    TREE_PURPOSE is ANON_AGGR_TYPE_FIELD.

    Note, CWG3130 fortunately disallows attempts to create a different object
    of ANON_AGGR_TYPE_P type (will need to implement that part), so the other
    worries from PR124991 (that one can create a variable or member or
parameter
    etc. with the anon union type and get confused by ANON_AGGR_TYPE_FIELD on
it
    or trying to tweak lookup rules etc.) are gone.

    2026-05-07  Jakub Jelinek  <[email protected]>

            PR c++/124991
            * cp-tree.h (struct lang_type): Document typeinfo_var member.
            (get_classtype_typeinfo_var): New inline function.
            (CLASSTYPE_TYPEINFO_VAR): Use it.
            (set_classtype_typeinfo_var): New inline function.
            (SET_CLASSTYPE_TYPEINFO_VAR): Define.
            (get_anon_aggr_type_field): New inline function.
            (ANON_AGGR_TYPE_FIELD): Use it.
            (set_anon_aggr_type_field): New inline function.
            (SET_ANON_AGGR_TYPE_FIELD): Define.
            * decl.cc (fixup_anonymous_aggr): Use SET_ANON_AGGR_TYPE_FIELD
            instead of ANON_AGGR_TYPE_FIELD.
            * module.cc (trees_in::read_class_def): Use
            SET_CLASSTYPE_TYPEINFO_VAR instead of setting
            CLASSTYPE_TYPEINFO_VAR and do it even for ANON_AGGR_TYPE_P
            types.  Use SET_ANON_AGGR_TYPE_FIELD instead of setting
            ANON_AGGR_TYPE_FIELD.
            * rtti.cc (get_tinfo_decl_direct): Use SET_CLASSTYPE_TYPEINFO_VAR
            instead of setting CLASSTYPE_TYPEINFO_VAR.
            * semantics.cc (finish_member_declaration): Use
            SET_ANON_AGGR_TYPE_FIELD instead of setting ANON_AGGR_TYPE_FIELD.

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

    Reviewed-by: Jason Merrill <[email protected]>
    (cherry picked from commit 6481ee18e339356e3f5ff65428224ee4c500bc41)

Reply via email to