From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10644 invoked by alias); 12 Jun 2003 12:59:57 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 10580 invoked by uid 48); 12 Jun 2003 12:59:57 -0000 Date: Thu, 12 Jun 2003 12:59:00 -0000 From: "mike.reed@amadron.com" To: gcc-bugs@gcc.gnu.org Message-ID: <20030612125956.11174.mike.reed@amadron.com> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/11174] New: derived class can access protected base class member function through pointer to member function X-Bugzilla-Reason: CC X-SW-Source: 2003-06/txt/msg01453.txt.bz2 List-Id: PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11174 Summary: derived class can access protected base class member function through pointer to member function Product: gcc Version: 3.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: mike.reed@amadron.com CC: gcc-bugs@gcc.gnu.org Reading specs from /usr/gcc3local/lib/gcc-lib/i686-pc-linux-gnu/3.3/specs Configured with: ../gcc-3.3/configure --prefix=/usr/gcc3local --enable-languages=c,c++ Thread model: posix gcc version 3.3 With the following code: class A { protected: void foo() {} public: A(); }; class B : public A { void bar() { A a; a.foo(); void (A::*pmf)() = &A::foo; // 1 (a.*pmf)(); // 2 } }; Compilation gives: g++ -W -Wall -ansi -pedantic -c pmf.cpp pmf.cpp: In member function `void B::bar()': pmf.cpp:3: error: `void A::foo()' is protected pmf.cpp:12: error: within this context Compilation exited abnormally with code 1 at Thu Jun 12 10:28:26 But note that I am able to call the protected member function of the external object via a pointer to member function (PMF). Looking at the C++ spec (11.5 example see void D2::mem...) I think the line labelled 1 should be ill-formed but since the compiler doesn't think so I am able to gain access to the protected function on the line labelled 2.