On Tue, Jan 13, 2026 at 08:40:10PM -0500, Marek Polacek wrote:
> > So it seems to me &[:^^anon-mem:] should give a regular pointer rather than
> > a pointer to member.
>
> This (and the code in the previous DECL_ANON_UNION_VAR_P comment) are
> to be changed by
> <https://forge.sourceware.org/marek/gcc/pulls/142/commits/8a9e9c33134a75472c9dbaa2ac1b5a5b7db763bd>
> but there are mangling issues to be resolved/XFAILd.
In particular given reduced mangle1.C:
// { dg-do compile { target c++26 } }
// { dg-additional-options "-freflection -O0" }
namespace NS2 {
static union { int au; };
struct X { union { int a; }; };
template <typename T>
struct Y { union { T a; }; };
}
template <int N, decltype (^^int) I>
void bar () {}
void baz (int x) {
bar <222, ^^NS2::au> (); // non-static data member
bar <223, ^^NS2::X::a> (); // non-static data member
bar <224, ^^NS2::Y <int>::a> (); // non-static data member
}
// { dg-final { scan-assembler "_Z3barILi222ELDmdm2auEEvv" } }
// { dg-final { scan-assembler "_Z3barILi223ELDmdm3NS21XUt_1aEEvv" } }
// { dg-final { scan-assembler "_Z3barILi224ELDmdm3NS21YIiEUt_1aEEvv" } }
Before the above pull request, we used to mangle it as shown in the
scan-assembler. That is wrong for 2 reasons, the au mangling doesn't
show in any way that it is NS2::au, if there would be another
instantiation with namespace NSD3 { static union { long au; }; }
and ^^NS3::au, it would mangle the same (that is from mangling
DECL_ANON_UNION_VAR_P VAR_DECL). And the Ut_ in there is I think
wrong too, https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling.named
says:
Unnamed class, union, and enum types that aren't closure types, that haven't
acquired a "name for linkage purposes" (through a typedef), and that
___aren't anonymous union types___, follow the same rule when they are defined
in class scopes, with the underlying <unqualified-name> an <unnamed-type-name>
of the form
<unnamed-type-name> ::= Ut [ <nonnegative number> ] _
For NS2::X::a and NS2::Y <int>::a, there is anonymous union, so it
should I think mangle as nothing and not as Ut_.
Now, with the above pull request except for the mangle.cc hunk, the mangling
is
_Z3barILi222ELDmdm3NS28._anon_02auEEvv
_Z3barILi223ELDmdm3NS21XUt_1aEEvv
_Z3barILi224ELDmdm3NS21YIiEUt_1aEEvv
so no changes for the second two, and the terribly ugly 8._anon_0 in the
first one.
And with the mangle.cc hunk it is
_Z3barILi222ELDmdm3NS22auEEvv
_Z3barILi223ELDmdm3NS21X1aEEvv
_Z3barILi224ELDmdm3NS21YIiE1aEEvv
which looks reasonable to me. Now, I was wondering if one couldn't have
some named class sandiched in between two anonymous unions, like
static union { struct S { union { int au; }; } s; };
but that is rejected, so maybe that hunk is good enough for reflections
and I should just adjust mangle1.C for that and maybe later we should
inspect write_unnamed_type_name or its callers that it doesn't emit
anything for anonymous unions.
And I guess for both reflection and mangling a question is about
anonymous structures as GNU extensions, I guess we don't cover them
much in reflection testsuite.
Jakub