]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: anonymous union member reference [PR105452]
authorJason Merrill <jason@redhat.com>
Thu, 30 Mar 2023 03:27:38 +0000 (23:27 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 30 Mar 2023 22:25:58 +0000 (18:25 -0400)
commit58df5350753c00f140c86e60ba5ce0cac686ec4b
treeb8daec4b5229dd4df17937a52382b8eab4abd06e
parent85131af0603c0af2aa6b40de6cc929905f22bd50
c++: anonymous union member reference [PR105452]

While parsing the anonymous union, we don't yet know that it's an anonymous
union, so we build the reference to 'v' in the static_assert relative to the
union type.  But at instantiation time we know it's an anonymous union, so
we need to avoid trying to check access for 'v' in the union again; the
simplest approach seemed to be to make accessible_p step out to the
containing class.

While looking at this I also noticed that we were having trouble with DMI in
an anonymous union referring to members of the containing class; there
we just need to give current_class_ptr the right type.

PR c++/105452

gcc/cp/ChangeLog:

* search.cc (type_context_for_name_lookup): New.
(accessible_p): Handle anonymous union.
* init.cc (maybe_instantiate_nsdmi_init): Use
type_context_for_name_lookup.
* parser.cc (cp_parser_class_specifier): Likewise.
* cp-tree.h (type_context_for_name_lookup): Declare.

gcc/testsuite/ChangeLog:

* g++.dg/lookup/anon8.C: New test.
gcc/cp/cp-tree.h
gcc/cp/init.cc
gcc/cp/parser.cc
gcc/cp/search.cc
gcc/testsuite/g++.dg/lookup/anon8.C [new file with mode: 0644]