The following code can't be compiled by gcc 4.0.2:

class Base {
public:
    class Nested {};
};

class Derived:public Base {
public:
    class Nested {
    public:
        void m();
    };
    class AnotherNested {
        friend class Nested; // gcc 4.0.2 takes it as 'Base::Nested'
        //friend class Derived::Nested; // this is needed in order to
be compiled by gcc 4.0.2
#line 14
        AnotherNested() {}
    };
};

void Derived::Nested::m() {
#line 18
    Derived::AnotherNested instance;

}

should the first friend decl refer to Base::Nested or Derived::Nested?

The code is refused by gcc 4.0.2:
  a.cpp:   In member function 'void Derived::Nested::m()':
  a.cpp:14: error: 'Derived::AnotherNested::AnotherNested()' is private
  a.cpp:18: error: within this context
because gcc 4 takes for granted the friend refers to Base::Nested.
However, e.g. gcc 3.4 takes it as Derived::Nested.
Declaring the friend the second way:
  friend class Derived::Nested;
works in gcc 4.0.2, but it uses not-yet-fully-declared class Derived, which
e.g.
can't be compiled by VC 6.0.


-- 
           Summary: friend class nested in derived class problem
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tomas dot sieger at seznam dot cz


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

Reply via email to