From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22388 invoked by alias); 26 May 2004 19:21:19 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22373 invoked by uid 48); 26 May 2004 19:21:18 -0000 Date: Thu, 27 May 2004 11:47:00 -0000 Message-ID: <20040526192118.22372.qmail@sourceware.org> From: "bangerth at dealii dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20040526185537.15664.igodard@pacbell.net> References: <20040526185537.15664.igodard@pacbell.net> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/15664] Linker fails to find (inline) function X-Bugzilla-Reason: CC X-SW-Source: 2004-05/txt/msg03111.txt.bz2 List-Id: ------- Additional Comments From bangerth at dealii dot org 2004-05-26 19:21 ------- Your code looks like this: ------------------- templateclass A1, templateclass A2> bool operator==(const Powerbase& p1, const Powerbase& p2); template class Alloc> class Powerbase { templateclass A2> friend bool operator==(const Powerbase& p1, const Powerbase& p2); }; template class A1, templateclass A2> inline bool operator==(const Powerbase& p1, const Powerbase& p2) { return p1.Relop(p2, Powerbase::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