From: Marek Polacek Date: Fri, 16 Jan 2026 22:22:58 +0000 (-0500) Subject: c++/reflection: use context_for_name_lookup X-Git-Tag: basepoints/gcc-17~1920 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f727cb7e7d42e4bfc8f36f8460489b1705528409;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index 8f85a6bab5d..9e2eeab05bc 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