diff options
author | Patrick Palka <ppalka@redhat.com> | 2023-03-24 14:51:24 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2023-03-24 14:51:24 -0400 |
commit | bbf2424c57c2e13d1a972c4ef4e871c3119b9cb4 (patch) | |
tree | 9814580fb3f609a1ab9359eefa560f76b5badd75 /gcc/go/go-gcc.cc | |
parent | 1f641d6aba284e0c277e6684cd6b2c73591cd14d (diff) | |
download | gcc-bbf2424c57c2e13d1a972c4ef4e871c3119b9cb4.zip gcc-bbf2424c57c2e13d1a972c4ef4e871c3119b9cb4.tar.gz gcc-bbf2424c57c2e13d1a972c4ef4e871c3119b9cb4.tar.bz2 |
c++: outer 'this' leaking into local class [PR106969]
Here when resolving the implicit object for '&wrapped' within the
local class Foo, we expect to obtain a dummy object of type Foo& since
there's no 'this' available in this context. And yet at this point
current_class_ref still corresponds to the outer class Context (and is
const), which confuses maybe_dummy_object into propagating the cv-quals
of current_class_ref and returning an object of type const Foo&. Thus
decltype(&wrapped) wrongly yields const int* instead of int*.
The problem ultimately seems to be that the 'this' from the enclosing
class appears available for use when parsing the local class, but 'this'
shouldn't persist across classes like that. This patch fixes this by
clearing current_class_ptr/ref before parsing a class definition.
After this change, for the test name-clash11.C in C++98 mode we would
now complain about an invalid use of 'this' in e.g.
ASSERT (sizeof (this->A) == 16);
due to the way the test defines the ASSERT macro via a local class.
This patch redefines the macro using a local typedef instead.
PR c++/106969
gcc/cp/ChangeLog:
* parser.cc (cp_parser_class_specifier): Clear current_class_ptr
and current_class_ref sooner, before parsing a class definition.
gcc/testsuite/ChangeLog:
* g++.dg/lookup/name-clash11.C: Fix ASSERT macro definition in
C++98 mode.
* g++.dg/lookup/this2.C: New test.
Diffstat (limited to 'gcc/go/go-gcc.cc')
0 files changed, 0 insertions, 0 deletions