This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
template/friend bug(s)
- To: <gcc-bugs at gcc dot gnu dot org>
- Subject: template/friend bug(s)
- From: "Paul J. Lucas" <pjl at interval dot com>
- Date: Thu, 7 Jun 2001 10:17:34 -0700 (PDT)
The attached program fails under g++ 2.96:
$ g++ -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.96/specs
gcc version 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)
$ g++ gcc-bug.c
gcc-bug.c: In function `int main ()':
cc-bug.c:39: no match for `B & == int &'
If you undefine TEMPLATE, the code compiles. The code is valid
regardless of whether the class is a template.
Alternatively, if you undefine FRIEND, the code compiles. The
code is valid regardless of whether operator== is declared
inline as a friend vs. at file scope.
This code compiles correctly (in all variants) under 2.95.
- Paul
/* ----- CUT ----- CUT ----- CUT ----- CUT ----- CUT ----- CUT ----- */
#include <iostream>
#define TEMPLATE /**/
#ifdef TEMPLATE
template< class T > class A;
template<>
#define A_CLASS A<int>
#else
#define A_CLASS A
#endif
struct A_CLASS {
#define FRIEND /**/
#ifdef FRIEND
friend bool operator==( A_CLASS const&, int ) {
cerr << "operator==( A&, int )" << endl;
return false;
}
#endif
};
#ifndef FRIEND
inline bool operator==( A_CLASS const&, int ) {
cerr << "operator==( A&, int )" << endl;
return false;
}
#endif
main() {
A_CLASS a;
int i;
a == i;
}