From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1C36C385843A; Fri, 24 Mar 2023 18:51:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C36C385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679683897; bh=Ty5AJsPOSc2a0Zo5J/1vMcYeXLhkFyH5slZUOLnfsmY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nxYBQojoj/8w36tLzLCH/2Czru5AlAQ+DLCsP8+rT6GwAL61R+n7HsUMfvUmsokE7 QfYAkjs2UN4vqdFSEBQFGEmpQdJEYAUt/geFbpbd/giwFuyyWg0OY6qlDmBElXfr/e YvO+b2A+DJNjDk4i+TdAok2ea6AjhZD8TOZorsDo= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106969] [12/13 Regression] member function constness incorrectly propagates to local class member function return type deduction Date: Fri, 24 Mar 2023 18:51:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: ppalka at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106969 --- Comment #3 from CVS Commits --- The master branch has been updated by Patrick Palka : https://gcc.gnu.org/g:bbf2424c57c2e13d1a972c4ef4e871c3119b9cb4 commit r13-6856-gbbf2424c57c2e13d1a972c4ef4e871c3119b9cb4 Author: Patrick Palka Date: Fri Mar 24 14:51:24 2023 -0400 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) =3D=3D 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.=