971031 and 971105: friendly template functions are not instantiated

Kevin Buhr buhr@stat.wisc.edu
Fri Nov 7 13:28:00 GMT 1997


buhr@stat.wisc.edu (Kevin Buhr) writes:
>
> Here's an architecture-independent bug in template instantiation.

To follow up to my own message, after some poking around I discovered
that "-fguiding-decls" makes the problem disappear, so perhaps I was
relying on an obsolete language feature for my particular test case.
However, I originally noticed the problem in the context of the
following code snippet:

#include <iterator>

main()
{
	istream_iterator<int> first(cin);
	istream_iterator<int> last;

	if (first == last)
		;
}

which produces an undefined reference to the "operator==" call, since
"operator==" is declared as a friend of the "istream_iterator" class
template.  (Again, "-fguiding-decls" makes the problem disappear.)

If I understand correctly, the default "-fno-guiding-decls" should
*not* instantiate a templated "f" here:

     template <class T>
     void f(T x) {};

     class foo { 
	     friend void f(foo x);  // no-guiding-decls means this is
				    // a non-template "f"
     };

but it *should* instantiate here:

     template <class T>
     void f(foo<T> x) {};

     template <class T>
     class foo {
	     friend void f(foo x);  // hey! this should be 
				    // the template version!
     };

and it doesn't.

Can someone with a clue help enlighten me?  Thanks.

Kevin <buhr@stat.wisc.edu>



More information about the Gcc-bugs mailing list