[gcc r16-6884] c++/reflection: use context_for_name_lookup

Marek Polacek mpolacek@gcc.gnu.org
Sun Jan 18 15:50:27 GMT 2026


https://gcc.gnu.org/g:f727cb7e7d42e4bfc8f36f8460489b1705528409

commit r16-6884-gf727cb7e7d42e4bfc8f36f8460489b1705528409
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Jan 16 17:22:58 2026 -0500

    c++/reflection: use context_for_name_lookup
    
    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>

Diff:
---
 gcc/cp/reflect.cc | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index 8f85a6bab5dd..9e2eeab05bc7 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -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


More information about the Gcc-cvs mailing list