Fixes a bogus "'Cls::<unnamed union>' is not a base of 'const Cls'" error
when user tries to do a class member lookup using splice with reflection of
anon union member.
PR c++/123642
gcc/cp/ChangeLog:
* typeck.cc (finish_class_member_access_expr): Change context lookup
to handle anon union members.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/member4.C: Remove expected error.
* g++.dg/reflect/anon4.C: New test based on original bug report.
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
|| TREE_CODE (name) == CONST_DECL
|| TREE_CODE (name) == FUNCTION_DECL
|| DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (name))))
- scope = DECL_CONTEXT (OVL_FIRST (name));
+ scope = context_for_name_lookup (OVL_FIRST (name));
if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
{
--- /dev/null
+// PR c++/123642
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+struct foo
+{
+ int i;
+ union
+ {
+ int a;
+ long b;
+ union
+ {
+ double c;
+ };
+ };
+};
+
+void test ()
+{
+ constexpr foo bar { .i = 11, .a = 1 };
+
+ static_assert (bar.a == 1);
+ static_assert (bar.[: ^^foo::a :] == 1);
+
+ static_assert (bar.*(&foo::a) == 1);
+ static_assert (bar.*&[: ^^foo::a :] == 1);
+
+ constexpr foo bar1 { .i = 42, .c = 3.14 };
+
+ static_assert (bar1.c == 3.14);
+ static_assert (bar1.[: ^^foo::c :] == 3.14);
+}
struct D { int i; };
auto c = C{.i=2};
-auto v = c.[:^^C::i:]; // { dg-error "not a base" }
+auto v = c.[:^^C::i:];
auto e = c.[: ^^D::i :]; // { dg-error "not a base" }