https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124991
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Works with clang/EDG doesn't necessarily means it is desirable for C++.
Anyway, I guess C++26 doesn't prohibit either of that.
The
#include <meta>
struct X { union { char b; float c; }; };
typename [: parent_of (^^X::b) :] a { .c = 6 };
testcase I've mentioned also works with GCC unless you use typeid on that.
But I'm worrying that it only works by accident, or more likely one needs to
extend it a little bit such that it misbehaves.
Maybe it needs to be
struct Y { typename [: parent_of (^^X::b) :] z; } y;
and then see what happens when one uses y.z etc.
The issue is that GCC's implementation of anonymous unions (and anonymous
structure extension) is implemented by marking the type:
ANON_AGGR_TYPE_P / ANON_UNION_TYPE_P / ANON_AGGR_TYPE_FIELD
rather than marking the nameless VAR_DECL or FIELD_DECL with that type.
If one can reflect the type of this nameless VAR_DECL/FIELD_DECL and use it as
a type for something completely different, and if C++ mandates that it is the
same type,
i.e. that e.g. for the above
static_assert (type_of (parent_of (^^X::b)) == type_of (^^a));
then I guess we have to stop tracking
ANON_AGGR_TYPE_P/ANON_UNION_TYPE_P/ANON_AGGR_TYPE_FIELD on the union and have
flags for it on the VAR_DECL/FIELD_DECL itself.
Unfortunately having the flags and ANON_AGGR_TYPE_FIELD on the type has
significant advantages, the thing is that when we have a FIELD_DECL inside of
the anon union and want to create access path object.<anon>.c, we have just
DECL_CONTEXT of the FIELD_DECl which is the type but without flags and
ANON_AGGR_TYPE_FIELD it is hard to find out it is in anon union and find the
corresponding unnamed FIELD_DECL. But when the type is used in unrelated
context, we don't want such handling obviously...