This code:
   class   f1 {
       class   f2 {
           class f3;
           friend
           void bar(f1::f2::f3 arg);
           class f3 {};
           };
       };
   void    bar(f1::f2::f3 arg) {}
gets you:
   foo.cc: In function ‘void bar(f1::f2::f3)’:
   foo.cc:2: error: ‘class f1::f2’ is private
   foo.cc:9: error: within this context

If I change it to:
   class   f1 {
       friend
       void bar(f1::f2::f3 arg);
       class   f2 {
           class f3;

           class f3 {};
           };
       };
   void    bar(f1::f2::f3 arg) {}
I of course get:
   foo.cc:4: error: ‘f1::f2::f3’ has not been declared
   foo.cc: In function ‘void bar(f1::f2::f3)’:
   foo.cc:5: error: ‘class f1::f2’ is private
   foo.cc:10: error: within this context
   foo.cc:7: error: ‘class f1::f2::f3’ is private
   foo.cc:10: error: within this context

Changing the friend to:
    friend
    void ::bar(f1::f2::f3 arg);
doesn't change anything.

Seems to me that a friend of an inner class should see anything that class can
see, including outer classes. The friend declaration might be expecting that
bar is a member function of f1, but explicit ::bar to tell the compiler that
it's global doesn't work either.

Is this a bug or have I found another language feature?


-- 
           Summary: friends of nested classes don't see outer classes
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


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

Reply via email to