The compiler is reporting "no match" for an friend operator==() which happens to be correctly defined. The class for which the operator is defined is a specialization of a class template. This inability to find the right operator only occurs, to my knowledge, when the operator is defined as a friend function inside a template class specialization. The error also goes away with one very simple yet apparently meaningless change, which in my example code can be enabled with '-DTEST'. [bgreen@pc125 tmp]$ g++ -c mytest2.C mytest2.C: In function `bool operator== (const cell &, const cell &)': mytest2.C:35: no match for `const myval<int> & == const myval<int> &' mytest2.C:34: candidates are: bool operator== (const cell &, const cell &) [bgreen@pc125 tmp]$ [bgreen@pc125 tmp]$ g++ -DTEST -c mytest2.C [bgreen@pc125 tmp]$ Release: gcc version 2.97 20001112 (experimental) Environment: uname -a: Linux pc125.nas.nasa.gov 2.2.16-22smp #1 SMP Tue Aug 22 16:39:21 EDT 2000 i686 unknown How-To-Repeat: template <class T> class myval { T d; public: myval(const myval &v) : d(v.d) {} friend bool operator==(const myval<T>& lhs, const myval<T>& rhs) { return lhs.d == rhs.d; } }; template<> class myval<int> { int d; public: myval(const myval &v) : d(v.d) {} friend bool operator==(const myval<int>& lhs, const myval<int>& rhs) { return lhs.d == rhs.d; } }; class cell { myval<int> v; public: #ifdef TEST cell(const myval<int> &in) : v(in) {} #endif friend bool operator==(const cell& lhs, const cell& rhs) { return lhs.v == rhs.v; } };
Fix: Defining the friend function outside the class does not work either, but rather highlights a different bug. It is possible to define operator==() as a member function instead, and that works as a workaround.
*** This bug has been marked as a duplicate of 764 ***
From: nathan@gcc.gnu.org To: bgreen@nas.nasa.gov, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: c++/807 Date: 24 Nov 2000 09:51:23 -0000 Synopsis: g++ 2.96 (20000731) + 2.97 (20001112) name resolution bug in friend definition in specialized template class. State-Changed-From-To: open->analyzed State-Changed-By: nathan State-Changed-When: Fri Nov 24 01:51:23 2000 State-Changed-Why: confirmed as a bug -- possible duplicate of 764 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=807&database=gcc
State-Changed-From-To: analyzed->closed State-Changed-Why: Works under: gcc version 3.0 20010507 (prerelease)
From: rodrigc@gcc.gnu.org To: bgreen@nas.nasa.gov, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org, rodrigc@gcc.gnu.org Cc: Subject: Re: c++/807 Date: 25 May 2001 08:13:01 -0000 Synopsis: g++ 2.96 (20000731) + 2.97 (20001112) name resolution bug in friend definition in specialized template class. State-Changed-From-To: analyzed->closed State-Changed-By: rodrigc State-Changed-When: Fri May 25 01:13:01 2001 State-Changed-Why: Works under: gcc version 3.0 20010507 (prerelease) http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=807&database=gcc