friends in template class or gcc bug ?
Levente Farkas
!spam-lfarkas@mindmaker.hu
Tue Mar 14 05:31:00 GMT 2000
hi,
what's the problem with the following code ?
----------
#include <iostream>
using namespace std;
template <class T>
struct A
{
T x;
A(T t) : x(t) {}
friend ostream& operator<<(ostream&, const A&);
};
template <class T>
inline ostream& operator<<(ostream& stream, const A<T>& a)
{
stream << a.x;
return stream;
}
int main()
{
A<int> a(2);
cout << a;
return 0;
}
----------
from gcc manual (2.95.2):
----------
-Wno-non-template-friend (C++ only)
Disable warnings when non-templatized friend functions are
declared within a template. With the advent of explicit template
specification support in g++, if the name of the friend is an
unqualified-id (ie, `friend foo(int)'), the C++ language
specification demands that the friend declare or define an
ordinary, nontemplate function. (Section 14.5.3). Before g++
implemented explicit specification, unqualified-ids could be
interpreted as a particular specialization of a templatized
function. Because this non-conforming behavior is no longer the
default behavior for g++, `-Wnon-template-friend' allows the
compiler to check existing code for potential trouble spots, and
is on by default. This new compiler behavior can also be turned
off with the flag `-fguiding-decls', which activates the older,
non-specification compiler code, or with
`-Wno-non-template-friend' which keeps the conformant
compiler code but disables the helpful warning.
----------
what does this mean ? I can't understand ? as I can read from the
standard the above is a correct code, couldn't ?
look at stroustrup's book page 347 and 855 or in the
"1997 C++ Public Review Document" 14.5.3.
-- lfarkas
"The only thing worse than not knowing the truth is
ruining the bliss of ignorance."
More information about the Gcc
mailing list