]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: fix ICE on is_accessible [PR124241]
authorchzn@mail.ustc.edu.cn <chzn@mail.ustc.edu.cn>
Mon, 4 May 2026 13:22:53 +0000 (21:22 +0800)
committerJason Merrill <jason@redhat.com>
Mon, 4 May 2026 19:28:41 +0000 (15:28 -0400)
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>
gcc/cp/search.cc
gcc/testsuite/g++.dg/reflect/is_accessible2.C

index e098362fed77762f97de332a59836bbd8a6a34dd..5d00ce3d8260156d1b233c7200cb858b00022f60 100644 (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]
 
index 8e69c1851da749203a15303cff30b3567d1b25b2..10139f12b2c9ea58ee3ef8b8d79071fc876dbe21 100644 (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)));