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

             Bug #: 53116
           Summary: protected member access from derived template
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: lex4...@gmail.com


According to "11.4 Protected member access" part of C++11 standard, member
function of derived class has no access to protected member of base class
through pointer to member class. In example below, we have base class "B",
derived classes D and Di. Either of them has access to B::f() through "this",
it is OK. D has not access through "B *" pointer, it is OK. But Di has access
through "B *" and it is a bug. The only difference between D and Di that Di is
template class.

I have tested it with "template <typename T>" template declaration, behavior is
the same.

Example:

class B
{
protected:
    void f();
};

class D: public B
{
public:
    void k()
    {
        f(); // this->f(), no error, OK
        //static_cast<B *>(0)->f(); // error here, OK
    }
};

template <int size>
class Di: public B
{
public:
    void k()
    {
        f(); // this->f(), no error, OK
        static_cast<B *>(0)->f(); // no error here, BUG
    }
private:
    int m_field[size];
};

int main() {}

Reply via email to