From 822c7840922d957fede19e6f11d94160772cd454 Mon Sep 17 00:00:00 2001 From: "chzn@mail.ustc.edu.cn" Date: Mon, 4 May 2026 21:22:53 +0800 Subject: [PATCH] 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 --- gcc/cp/search.cc | 2 ++ gcc/testsuite/g++.dg/reflect/is_accessible2.C | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index e098362fed7..5d00ce3d826 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -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] diff --git a/gcc/testsuite/g++.dg/reflect/is_accessible2.C b/gcc/testsuite/g++.dg/reflect/is_accessible2.C index 8e69c1851da..10139f12b2c 100644 --- a/gcc/testsuite/g++.dg/reflect/is_accessible2.C +++ b/gcc/testsuite/g++.dg/reflect/is_accessible2.C @@ -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)));