C++ Reflection Fixes Sharing of Type Information for Anonymous Unions
GCC now handles reflection on anonymous unions/structs correctly by differentiating between `CLASSTYPE_TYPEINFO_VAR` and `ANON_AGGR_TYPE_FIELD`. This prevents…
GCC now correctly handles reflection on anonymous unions and structs within classes by distinguishing between CLASSTYPE_TYPEINFO_VAR (for typeid) and ANON_AGGR_TYPE_FIELD (for anonymous union/struct members). Previously, the compiler shared the same tree node for both, which led to internal compiler errors when reflection was used on anonymous unions. The fix uses a TREE_LIST to store both when necessary, avoiding an increase in the size of the lang_type struct.
In Details
This commit addresses PR124991 related to C++ reflection and the sharing of CLASSTYPE_TYPEINFO_VAR and ANON_AGGR_TYPE_FIELD in cp-tree.h. The typeinfo_var element of lang_type is used for both typeid and anonymous aggregate fields. The fix uses a TREE_LIST to store both VAR_DECL and FIELD_DECL when reflection is used.
For Context
Anonymous unions and structs are unnamed data structures declared within a class. This commit addresses a potential issue in the C++ compiler related to how type information is stored for these anonymous structures, especially when reflection (examining the structure of code at runtime) is involved. It ensures that the compiler can correctly differentiate between different uses of type information, preventing internal errors and improving the reliability of reflection.