From Bugzilla Helper: User-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.2.16-22 i686) Reproducible: Always Steps to Reproduce: 1.gcc matrix-gccbug.cxx 2. 3. Actual Results: In file included from matrix-gccbug.cxx:2: matrix.hxx:39: warning: friend declaration `matrix<T> operator+ (const matrix<T> &, const matrix<T> &)' matrix.hxx:39: warning: declares a non-template function matrix.hxx:39: warning: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning. matrix.hxx:40: warning: friend declaration `ostream &operator<< (ostream &, const matrix<T> &)' matrix.hxx:40: warning: declares a non-template function /tmp/ccpqC8WI.o: In function `main': /tmp/ccpqC8WI.o(.text+0x68): undefined reference to `operator+(matrix<int> const &, matrix<int> const &)' /tmp/ccpqC8WI.o(.text+0x77): undefined reference to `cout' /tmp/ccpqC8WI.o(.text+0x7c): undefined reference to `operator<<(ostream &, matrix<int> const &)' /tmp/ccpqC8WI.o(.text+0x8b): undefined reference to `cout' /tmp/ccpqC8WI.o(.text+0x90): undefined reference to `operator<<(ostream &, matrix<int> const &)' /tmp/ccpqC8WI.o(.text+0x9f): undefined reference to `cout' /tmp/ccpqC8WI.o(.text+0xa4): undefined reference to `operator<<(ostream &, matrix<int> const &)' collect2: ld returned 1 exit status Expected Results: Clean compile. Run displays two matrices added to make thrid matrix. Expected results received from Compaq C++ for OpenVMS Alpha V 6.2. Expected results received from IBM C/C++ Tools V 2.01 for OS/2.
Created attachment 13083 [details] Sample source file
Created attachment 13084 [details] sample source file
Have reproduced with gcc-2.96-60 and gcc-2.96-69.
Why do you think this is a bug? The source does not follow ISO C++ spec and g++ even tells you step by step what you probably want to do and how. If you add: template<class T> class matrix; template<class T> matrix<T> operator+( const matrix<T>&, const matrix<T>& ); template<class T> ostream& operator<<( ostream& stream, const matrix<T>& value ); above template<class T> class matrix declaration, it compiles just fine and works. The fact that the 2 above mentioned compilers accepted it does not mean it is correct C++.
Thanks for the edification. I was thrown off by errors received when I attempted to implement the changes detailed in the above diagnostic messages. These errors were caused by using gcc instead of g++. It didn't help that none of the C++ books I referenced had an example of a template class friend function.