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++/49388] New: Template class can extend private nested class


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

           Summary: Template class can extend private nested class
           Product: gcc
           Version: 4.4.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: matthew_eanor@hotmail.com


GCC 4.4.5 will happily compile the following where the templated class extends
a private nested class.

#include <iostream>

class A {
private:
  class B {
  protected:
    void doSomething() {
      std::cout << "Here\n";
    }
  };
};

template<typename T>
class C : public A::B {
public:
  C() {
    this->doSomething();
  }
};

int main(void)
{
    C<int> c;
}


Access to A::B is private and compilation should fail rather than succeed. 

Although I have not personally tried this on a later compiler than 4.4.5, I
have been told that this same bug is present in 4.6.

Note. I originally raised this as a question here
(http://stackoverflow.com/questions/6325291/why-can-i-extend-a-private-nested-class-by-a-template-class)


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