[Bug c++/41050] Placement new not seeing base class protected functions

redi at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Aug 13 10:59:00 GMT 2009



------- Comment #4 from redi at gcc dot gnu dot org  2009-08-13 10:59 -------
(In reply to comment #2)
> Well, if the call is on foo then surely a foo can call; its own methods,

Yes, a foo can call its own methods, but a bar can only call them through a bar
object, not on an object with static type foo.  i.e. bar only has access to the
protected members of a foo that is a sub-object of a bar, and not otherwise.

> whereas if the call is on bar then a bar should see the protected methods of
> its base class foo. Either way it should be visible.

The call is not on a bar, it's on a foo.

Consider:

class foo
{
protected:
    int i;
};

class bar : public foo
{
public:
    void f()
    {
        this->i;                     // OK
        foo().i;                     // protected
        static_cast<foo*>(this)->i;  // protected
    }
};

This is the same situation as your testcase, bar is trying to access protected
members of a foo without going through a bar.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41050



More information about the Gcc-bugs mailing list