c++/reflection: fix ICE on is_accessible [PR124241]

Anonymous unions don't have their own access.
This patch fix the missing check for otype in accessible_p at search.cc.

gcc/cp/ChangeLog:

	PR c++/124241
	* search.cc (accessible_p): Call type_context_for_name_lookup
	for otype if it's anonymous union.

gcc/testsuite/ChangeLog:

	PR c++/124241
	* g++.dg/reflect/is_accessible2.C: Completed the TODO of the PR.

Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
chzn@mail.ustc.edu.cn
2026-05-04 21:22:53 +08:00
committed by Jason Merrill
parent 3c917d8d04
commit 822c784092
2 changed files with 3 additions and 2 deletions

View File

@@ -936,6 +936,8 @@ accessible_p (tree type, tree decl, bool consider_local_p)
/* Anonymous unions don't have their own access. */
if (ANON_AGGR_TYPE_P (type))
type = type_context_for_name_lookup (type);
if (ANON_AGGR_TYPE_P (otype))
otype = type_context_for_name_lookup (otype);
/* [class.access.base]

View File

@@ -454,8 +454,7 @@ static_assert (is_accessible (N::ra, gctx));
static_assert (!is_accessible (N::rb, gctx));
static_assert (!is_accessible (N::rc, gctx));
static_assert (is_accessible (N::ra, N::ctx));
// TODO: This case ICEs.
//static_assert (is_accessible (N::rb, N::ctx));
static_assert (is_accessible (N::rb, N::ctx));
static_assert (is_accessible (N::rc, N::ctx));
static_assert (is_accessible (N::ra, N::ctx.via (^^N)));
static_assert (is_accessible (N::rb, N::ctx.via (^^N)));