[cfe-dev] [Bug] Undefined reference to function template declared friend and defined in template class
John McCall
rjmccall at apple.com
Tue Mar 11 16:54:46 PDT 2014
On Mar 10, 2014, at 9:07 AM, suyog sarda <sardask01 at gmail.com> wrote:
> This is regarding g++ test case
> g++.old-deja/g++.pt/friend10.C
>
> template <class T>
> void f(T);
>
> template <class U>
> class C
> {
> template <class T>
> friend void f(T)
> {
> C<U> c;
> c.i = 3;
> }
>
> public :
>
> void g()
> {
> f(3.0);
> }
> int i;
> };
>
> int main ()
> {
> f(7);
> C<double> c;
> c.g();
> }
>
> Here, even when the body of function f() is defined, compiler throws error :
>
> In function `main':
> 19095.C:(.text+0x16): undefined reference to `void f<int>(int)'
> /tmp/19095-fd27b4.o: In function `C<double>::g()':
> 19095.C:(.text._ZN1CIdE1gEv[_ZN1CIdE1gEv]+0x1b): undefined reference to `void f<double>(double)'
> clang-3.5: error: linker command failed with exit code 1
>
> I have filed a bug related to this llvm.org/bugs/show_bug.cgi?id=19095
>
> g++ compiles this without any error.
>
> Please help in verifying if above is real bug. In my view this is a bug since function body has been defined and as it is declared friend it is a non-member function of class template.
It does look like a bug. Note that you can only instantiate this class template once, since the second instantiation would introduce a redefinition of f.
John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140311/ba417187/attachment.html>
More information about the cfe-dev
mailing list