This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11174] New: derived class can access protected base class member function through pointer to member function


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]