https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68089
Bug ID: 68089 Summary: c++ friend with template Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dushistov at mail dot ru Target Milestone: --- Here is code: #include <iostream> template<typename T> class C { template<typename U> // ???????? friend class C; template<typename U> friend bool operator == (C const& c1, C<U> const& c2) { return c1.i == c2.i; } int i; public: C(): i {0} {} C(int val): i {val} {} }; // template class C int main() { C<int> c1 {5}; C<char> c2 {5}; if (c1 == c2) std::cout << "All ok" << std::endl; else std::cout << "Very bad" << std::endl; return 0; } compile line: g++ -Wall -std=c++14 test4.cpp g++ -Wall -std=c++14 test4.cpp test4.cpp: In instantiation of 'bool operator==(const C<T>&, const C<U>&) [with U = char; T = int]': test4.cpp:28:13: required from here test4.cpp:15:9: error: 'int C<char>::i' is private int i; ^ test4.cpp:12:19: error: within this context return c1.i == c2.i; so even if bool operator == (C const& c1, C<U> const& c2) is friend of template<typename T> class C; it not allowed to access C<>::i, but clang compiles this code without errors.