]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: use context_for_name_lookup
authorMarek Polacek <polacek@redhat.com>
Fri, 16 Jan 2026 22:22:58 +0000 (17:22 -0500)
committerMarek Polacek <polacek@redhat.com>
Sun, 18 Jan 2026 15:45:34 +0000 (10:45 -0500)
We can simplify the code here by using context_for_name_lookup.

gcc/cp/ChangeLog:

* reflect.cc (check_splice_expr): Use context_for_name_lookup.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc

index 8f85a6bab5dd67ce3027536f8bed48bae11ba61e..9e2eeab05bc77397223e33bd2a2c6a9a0869c96e 100644 (file)
@@ -8387,18 +8387,13 @@ check_splice_expr (location_t loc, location_t start_loc, tree t,
      class C that is not an anonymous union."  */
   if (address_p
       && TREE_CODE (t) == FIELD_DECL
-      && ANON_UNION_TYPE_P (DECL_CONTEXT (t)))
+      && ANON_UNION_TYPE_P (DECL_CONTEXT (t))
+      && !TYPE_P (context_for_name_lookup (t)))
     {
-      tree c = CP_TYPE_CONTEXT (DECL_CONTEXT (t));
-      while (ANON_UNION_TYPE_P (c))
-       c = CP_TYPE_CONTEXT (c);
-      if (!TYPE_P (c))
-       {
-         if (complain_p)
-           error_at (loc, "unary %<&%> applied to an anonymous union member "
-                     "%qD that is not a direct member of a named class", t);
-         return false;
-       }
+      if (complain_p)
+       error_at (loc, "unary %<&%> applied to an anonymous union member "
+                      "%qD that is not a direct member of a named class", t);
+      return false;
     }
 
   /* [expr.prim.splice]/2: "The expression is ill-formed if S [the construct