http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60799
Bug ID: 60799 Summary: access checking within injected friend functions does not happen in the context of the enclosing class Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: eric.niebler at gmail dot com The following compiles with clang, but not with gcc-4.8.2 ///////////////////////////////////////////// template<typename T> struct foo; template<typename T> struct bar { private: template<typename U> friend struct foo; int x_; public: bar() : x_(0) {} }; template<typename T> struct foo { private: int x_; public: foo() : x_(0) {} friend bool operator==(foo<T> f, bar<T> b) { return f.x_ == b.x_; } }; int main() { foo<int> f; bar<int> b; bool i = (f == b); } //////////////////////////////////////////////// Result: test.cpp: In instantiation of ‘bool operator==(foo<int>, bar<int>)’: test.cpp:32:18: required from here test.cpp:10:7: error: ‘int bar<int>::x_’ is private int x_; ^ test.cpp:24:19: error: within this context return f.x_ == b.x_; ^