This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15664] Linker fails to find (inline) function
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 May 2004 19:21:18 -0000
- Subject: [Bug c++/15664] Linker fails to find (inline) function
- References: <20040526185537.15664.igodard@pacbell.net>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From bangerth at dealii dot org 2004-05-26 19:21 -------
Your code looks like this:
-------------------
template<typename E, template<typename>class A1, template<typename>class A2>
bool operator==(const Powerbase<E, A1>& p1, const Powerbase<E, A2>& p2);
template<typename E, template<typename> class Alloc>
class Powerbase
{
template<template<typename>class A2>
friend
bool operator==(const Powerbase<E, Alloc>& p1,
const Powerbase<E, A2>& p2);
};
template<typename E, template<typename> class A1, template<typename>class A2>
inline
bool operator==(const Powerbase<E, A1>& p1,
const Powerbase<E, A2>& p2) {
return p1.Relop(p2, Powerbase<E, A1>::equalOp);
}
-------------------------
The problem with it is that the friend declaration is not for the function
you have previously declared (easily seen by the fact that it has only one
instead of three template arguments). Thus, the compiler assumes that it
is a previously undeclared overload of operator== and injects it into the
global namespace. You therefore have two overloaded declarations, and the
compiler later on in the program happens to pick the one that was
declared in the friend declaration. It doesn't exist, though, thus the
linker error.
The general rule is: since there are no partial specializations for template
functions, the only thing you can declare a friend is a general template,
in this case the three-argument template. You can't declare only certain
possible instantiations of a template a friend.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15664