template/friend bug(s)
Paul J. Lucas
pjl@interval.com
Thu Jun 7 10:18:00 GMT 2001
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;
}
More information about the Gcc-bugs
mailing list