diff options
author | Jason Merrill <jason@redhat.com> | 2023-03-29 23:27:38 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-03-30 18:25:58 -0400 |
commit | 58df5350753c00f140c86e60ba5ce0cac686ec4b (patch) | |
tree | b8daec4b5229dd4df17937a52382b8eab4abd06e /gcc/cp/init.cc | |
parent | 85131af0603c0af2aa6b40de6cc929905f22bd50 (diff) | |
download | gcc-58df5350753c00f140c86e60ba5ce0cac686ec4b.zip gcc-58df5350753c00f140c86e60ba5ce0cac686ec4b.tar.gz gcc-58df5350753c00f140c86e60ba5ce0cac686ec4b.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp/init.cc')
-rw-r--r-- | gcc/cp/init.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index c5a55da..9571d18 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -597,7 +597,7 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain) DECL_INSTANTIATING_NSDMI_P (member) = 1; bool pushed = false; - tree ctx = DECL_CONTEXT (member); + tree ctx = type_context_for_name_lookup (member); processing_template_decl_sentinel ptds (/*reset*/false); if (!currently_open_class (ctx)) |