This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
specialization of friend template fct.
- To: egcs-bugs at cygnus dot com
- Subject: specialization of friend template fct.
- From: Stefan Schwarzer <sts at ica1 dot uni-stuttgart dot de>
- Date: Thu, 11 Jun 1998 00:03:55 +0200 (MET DST)
We use the following idiom to hack around a problem in one of
our compilers which does not correclty implement template friends.
As I read the CD2, this code should be ok and it compiles with
cxx-6.1 and KCC 3.3.
The latest ecgs-snapshot produces an internal error at the specialization
in line 39
23:50 margay_sts:~/bugs/kai> /local/egcs-19980608/bin/g++ simple_pair.cc
simple_pair.cc:39: Internal compiler error.
simple_pair.cc:39: Please submit a full bug report to `egcs-bugs@cygnus.com'.
23:54 margay_sts:~/bugs/kai> uname -a
OSF1 margay.ica1.uni-stuttgart.de V4.0 564.32 alpha
23:55 margay_sts:~/bugs/kai> cat simple_pair.cc
#include <iostream>
// offending statement:
// comment out to make bug (?) dissappear
using namespace std;
class A{};
class OUT{};
OUT & operator<<(OUT &o, const A &a){
std::cout << "OUT << A\n";
return o;
}
template<class T>
struct V {
V(T *a_): a(a_){}
// this is really a hack but should be ok according to CD2 14.5.3
template<class S>
friend OUT & operator<<(OUT &, const V<S> &);
//friend OUT & operator<<(OUT &, const V<A> &);
//friend OUT & operator<< <T>(OUT &, const V<T> &);
//friend OUT &operator<< <A>(OUT &o, const V<A> &va);
private:
T *a;
};
template<class T>
OUT &operator<< (OUT &o, const V<T> &v){
std::cout << "OUT << V<T>\n";
return o << *v.a;
}
// ok according to CD2 14.7 -- line 39
template<>
OUT &operator<< (OUT &o, const V<A> &va){
// same behavior: OUT &operator<< <A>(OUT &o, const V<A> &va){
std::cout << "OUT << V<A>\n";
return o << *va.a;
}
int main()
{
A a;
OUT o;
o << V<A>(&a);
}