http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52212
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-12 15:08:14 UTC --- (In reply to comment #0) > Note that the same function was earlier made a friend of class E, and so can > see F. If you leave out the second friending, you get: > foo.cc: In function âvoid foo1(D::E::F&)â: > foo.cc:2:8: error: âclass D::Eâ is private > foo.cc:9:21: error: within this context > which is correct; foo1 cannot see E without the second friend. But with both > friends foo1 should see everybody. Just to be clear, the problem is not that foo can't access the names, it's that the second declaration of foo appears in the scope of class D, and D cannot access the name D::E::F so you can't even declare foo there. Adding the extra friend decl allows foo to be declared there.