C++/Reflection: Fix ICE on is_accessible [PR124241].
Fixes an internal compiler error (ICE) when using `is_accessible` with anonymous unions by adding a missing check.
The compiler was experiencing an internal compiler error (ICE) when the is_accessible feature was used with anonymous unions. This commit fixes the issue by adding a check for the otype (the type being accessed) in the accessible_p function within search.cc. This ensures that the compiler correctly handles access checks for members of anonymous unions.
In Details
The ICE occurred due to a missing check for otype in the accessible_p function in search.cc. Anonymous unions don't have their own access control, so the access control of the enclosing type needs to be considered. The fix involves calling type_context_for_name_lookup for otype if it's an anonymous union. This ensures that the access check is performed in the correct context.
For Context
C++ reflection allows programs to inspect and manipulate their own structure at runtime. is_accessible is a reflection feature that checks if a member of a class or struct is accessible from a given context. This commit fixes a bug that caused the compiler to crash (an internal compiler error, or ICE) when using is_accessible with anonymous unions, which are a special kind of union without a name. The fix ensures that the compiler correctly handles access checks for members within anonymous unions, preventing the crash.