This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: friends in template class or gcc bug ?
- To: lfarkas at mindmaker dot hu
- Subject: Re: friends in template class or gcc bug ?
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Tue, 14 Mar 2000 21:35:13 +0100
- CC: gcc at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org
- References: <38CE3EF1.8094E74C@mindmaker.hu>
> what's the problem with the following code ?
It's ill-formed.
> 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.
Well, the reference to in the gcc manual was to section 14.5.3 of the
ISO C++ standard (ISO/IEC 14882:1998); the draft documents might be
different.
Anyway, in 14.5.3, it says
# For a friend function declaration that is not a template
# declaration:
Yes, this applies here:
friend ostream& operator<<(ostream&, const A&);
That is a function declaration, but not a template declaration.
# if the name of the friend is a qualified or unqualified templateid,
# ...
No, that is not the case.
# if the name of the friend is a qualifiedid and a matching
# nontemplate function is found
No, that is also not the case
# if the name of the friend is a qualifiedid and a matching
# specialization of a template function is found
Neither is this
# the name shall be an unqualifiedid that declares (or redeclares) an
# ordinary (nontemplate) function.
Since all else failed, we now know that the operator<< must be an
ordinary, non-template function. Since you are instantiating A<int>,
the signature of this friend will be
ostream& operator<<(ostream&, const A<int>&);
(as a normal function *not* as a template). Since you do not implement
that function, you get a linker error.
If you question this line of reasoning, please discuss it in one of
the public C++ fora first, eg. comp.lang.c++.moderated, or
comp.std.c++.
> "The only thing worse than not knowing the truth is
> ruining the bliss of ignorance."
Wisely spoken :-)
Regards,
Martin