On 1/17/26 8:49 AM, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK.
-- >8 --
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.
---
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 237f630d71b..d2c177476cf 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
base-commit: 56c143bca7c95559e5fb0882b649d94b3749e341