public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11174] New: derived class can access protected base class member function through pointer to member function
@ 2003-06-12 12:59 mike.reed@amadron.com
  2003-06-12 15:36 ` [Bug c++/11174] " giovannibajo@libero.it
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: mike.reed@amadron.com @ 2003-06-12 12:59 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2004-05-25 14:44 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-12 12:59 [Bug c++/11174] New: derived class can access protected base class member function through pointer to member function mike.reed@amadron.com
2003-06-12 15:36 ` [Bug c++/11174] " giovannibajo@libero.it
2003-06-15 13:54 ` lerdsuwa@gcc.gnu.org
2003-06-15 13:55 ` lerdsuwa@gcc.gnu.org
2003-08-01 15:25 ` lerdsuwa at gcc dot gnu dot org
2003-08-18 14:03 ` lerdsuwa at gcc dot gnu dot org
2003-08-19 12:55 ` cvs-commit at gcc dot gnu dot org
2003-08-19 12:55 ` lerdsuwa at gcc dot gnu dot org
2003-09-01  3:54 ` pinskia at gcc dot gnu dot org
2004-04-08 18:43 ` pinskia at gcc dot gnu dot org
2004-05-06 12:36 ` pinskia at gcc dot gnu dot org
2004-05-16 21:39 ` pinskia at gcc dot gnu dot org
2004-05-18 11:08 ` pinskia at gcc dot gnu dot org
2004-05-18 11:10 ` pinskia at gcc dot gnu dot org
2004-05-18 11:38 ` giovannibajo at libero dot it
2004-05-26 12:29 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).