Thanks for the patch. A few comments. Let's adjust the subject to start with "c++/reflection:". It's also quite long; maybe just say:
c++/reflection: anon union member from splice [PR123642] On Wed, Feb 18, 2026 at 01:27:51AM +0000, Valentyn Yukhymenko wrote: > Signed-off-by: Valentyn Yukhymenko <[email protected]> It is customary to briefly describe the motivation of the patch. Here we're fixing a bogus "not a base" error with unnamed unions. A ChangeLog entry is missing. In the Bugzilla you mention that gcc-mklog didn't work. You can try running gcc-git-customization.sh in contrib/, that should add various git aliases, and then you can use git gcc-commit-mklog and hopefully that produces the ChangeLog skeleton. You should also test every patch and say that you did so; e.g., Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? This patch breaks member4.C: FAIL: g++.dg/reflect/member4.C -std=c++26 (test for errors, line 13) but I think this change is right as per [class.mem.general/3 so just remove the dg-error. clang++ behaves the same as gcc with this patch. > --- > gcc/cp/typeck.cc | 10 ++++++++ > gcc/testsuite/g++.dg/reflect/anon4.C | 34 ++++++++++++++++++++++++++++ > 2 files changed, 44 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/reflect/anon4.C > > diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc > index 20ef2a4d6df..e54f10f0fb3 100644 > --- a/gcc/cp/typeck.cc > +++ b/gcc/cp/typeck.cc > @@ -3616,6 +3616,16 @@ finish_class_member_access_expr (cp_expr object, tree > name, bool template_p, > name = OVL_NAME (name); > } > > + if (TREE_CODE (name) == FIELD_DECL && ANON_UNION_TYPE_P (scope)) > + { > + tree c = CP_TYPE_CONTEXT (scope); > + while (ANON_UNION_TYPE_P (c)) > + c = CP_TYPE_CONTEXT (c); > + > + if (TYPE_P (c)) > + scope = c; > + } > + Instead of this, I'd change the else if (splice_p && ...) scope = DECL_CONTEXT (OVL_FIRST (name)); above to scope = context_for_name_lookup (OVL_FIRST (name)); which should work. > if (scope) > { > if (TREE_CODE (scope) == ENUMERAL_TYPE) > diff --git a/gcc/testsuite/g++.dg/reflect/anon4.C > b/gcc/testsuite/g++.dg/reflect/anon4.C > new file mode 100644 > index 00000000000..e40c727c3bb > --- /dev/null > +++ b/gcc/testsuite/g++.dg/reflect/anon4.C > @@ -0,0 +1,34 @@ > +// { dg-do compile { target c++26 } } > +// { dg-additional-options "-freflection" } > +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123642 Instead of this line, add // PR c++/123642 as the first line in the file. > + > +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); > +} > + Extra newline. Marek
