From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A953D3894C2C; Tue, 12 Jan 2021 16:58:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A953D3894C2C From: "ppalka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/58993] incorrectly accept access of protected member method from derived class template Date: Tue, 12 Jan 2021 16:58:31 +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: 4.7.3 X-Bugzilla-Keywords: accepts-invalid X-Bugzilla-Severity: normal X-Bugzilla-Who: ppalka at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ppalka at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc bug_status assigned_to 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jan 2021 16:58:31 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D58993 Patrick Palka changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ppalka at gcc dot gnu.org Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot g= nu.org --- Comment #8 from Patrick Palka --- (In reply to Jonathan Wakely from comment #5) > Warning-free testcase: >=20 > class base { > private: > void foo() { } > }; >=20 > template > struct bar : public base { > void test() { > (void) &base::foo; // should be rejected > } > }; >=20 > template <> > struct bar : public base { > void test() { > // &base::foo; // correctly rejected > } > }; >=20 > int main() { > bar().test(); > bar().test(); > } >=20 > Still accepted by trunk. >=20 >=20 > Clang says: >=20 > 58993.cc:9:23: error: 'foo' is a private member of 'base' > (void) &base::foo; // should be rejected > ^ > 58993.cc:3:10: note: declared private here > void foo() { } > ^ > 1 error generated. >=20 >=20 > and EDG says: >=20 > "58993.cc", line 9: error: function "base::foo" (declared at line 3) is > inaccessible > (void) &base::foo; // should be rejected > ^ > detected during instantiation of "void bar::test() [with T= =3Dint]" > at line 21 >=20 > 1 error detected in the compilation of "58993.cc". With GCC 11 (after the PR41437 patch), we reject the first access only if bar::test() is defined out-of-line: class base { private: int foo() { } }; template struct bar : public base { void test(); }; template void bar::test() { &base::foo; } int main() { bar().test(); } Investigating.=