egcs-970929: Missing symbols
Kurt Garloff
garloff@kg1.ping.de
Thu Oct 2 16:28:00 GMT 1997
On 2 Oct 1997, Alexandre Oliva wrote:
> C++ is not like that: a function and an instantiation of a template
> function with the same set of arguments are not the same.
AFAIK, the compiler is supposed to instantiate a templated function, when
it finds a matching prototype. This behaviour is uniquely defined, as long
as we don't need any type promotions and even if we do, there are rules
which the compiler can follow (R12.3 in Stroustrup 92).
There is a lot of code which would be broken otherwise, part of which are
some examples in Stroustrup. Did everything change since 1995 ?
> friend template functions must be declared before they are referred
> to, and any references to their declarations must have template
> braces.
>
> template <class T>
> class cplx;
> template <class T>
> T real (const cplx<T>& c);
> template <class T>
> ostream& operator << (ostream& ost, const cplx<T>& c);
>
> > template <class T>
> > class cplx
> > {
> [...] // note the empty angle brackets:
> > friend T real<> (const cplx<T>& c);
> > friend ostream& operator << <> (ostream&, const cplx<T>&);
> > };
>
> The changed-as-above code compiles and links successfully with the
> current release of gcc.
Yes, it does ...
The problem is that the above method of writing not only doubles the
little example program but most of the C++-Code I (and many others) use.
I got a numerical library which uses lots of friend functions ...
> In my previous message, where I wrote the linked successfully with the
> current release of gcc, I meant it did with the current snapshot of
> egcs. It obviously (and unfortunately) won't even compile with
> gcc-2.7.2.*, since it lacks the appropriate template handling code.
I'm sure gcc-2.7.2 is not correct in not compiling your code, but I'm
almost sure egcs-2.90.11 is wrong not compiling mine.
BTW, it is the only compiler I know that does not compile it. The Kai
C++ front end (which is VERY close to the upcoming standard) makes no
problems with templated functions. An old DEC C++ compiler does not
complain either.
Kurt Garloff, Dortmund
<K.Garloff@ping.de>
More information about the Gcc-bugs
mailing list