https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102995
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #2) > I suspect the original testcase is invalid code and clang is incorrect in > accepting it. You can limit the friendship to only the operator== that have the same second template operand if you need to limit the friendship slightly more: template<typename A, typename B> class First { public: First() = default; private: int GetId() const { return 1; } template<typename U, typename D> friend bool operator==(const First<U, B>& lhs, const First<D, B>& rhs); }; template<typename U, typename D, typename V> bool operator==(const First<U, V>& lhs, const First<D, V>& rhs) { return lhs.GetId() == rhs.GetId(); } int main() { First<int, bool> a; First<void *, bool> b; return a == b; }