This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/807: g++ 2.96 (20000731) + 2.97 (20001112) name resolution bug in friend definition in specialized template class.
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/807: g++ 2.96 (20000731) + 2.97 (20001112) name resolution bug in friend definition in specialized template class.
- From: bgreen at nas dot nasa dot gov
- Date: 14 Nov 2000 22:54:10 -0000
- Reply-To: bgreen at nas dot nasa dot gov
>Number: 807
>Category: c++
>Synopsis: g++ 2.96 (20000731) + 2.97 (20001112) name resolution bug in friend definition in specialized template class.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Tue Nov 14 14:56:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Bryan Green
>Release: gcc version 2.97 20001112 (experimental)
>Organization:
>Environment:
uname -a:
Linux pc125.nas.nasa.gov 2.2.16-22smp #1 SMP Tue Aug 22 16:39:21 EDT 2000 i686 unknown
>Description:
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]$
>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.
>Release-Note:
>Audit-Trail:
>Unformatted: