<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Mar 10, 2014, at 9:07 AM, suyog sarda <<a href="mailto:sardask01@gmail.com">sardask01@gmail.com</a>> wrote:<br><div><blockquote type="cite"><div dir="ltr">This is regarding g++ test case <br><h3><span style="font-weight:normal">g++.old-deja/g++.pt/friend10.C</span></h3><pre><i>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();
}</i></pre> <div><div><br></div><div>Here, even when the body of function <i>f()</i> is defined, compiler throws error :<br><br><i>In function `main':<br>19095.C:(.text+0x16): undefined reference to `void f<int>(int)'<br>
/tmp/19095-fd27b4.o: In function `C<double>::g()':<br>19095.C:(.text._ZN1CIdE1gEv[_ZN1CIdE1gEv]+0x1b): undefined reference to `void f<double>(double)'<br>clang-3.5: error: linker command failed with exit code 1</i><br>
<br></div><div>I have filed a bug related to this <a href="http://llvm.org/bugs/show_bug.cgi?id=19095">llvm.org/bugs/show_bug.cgi?id=19095</a><br><br></div><div>g++ compiles this without any error.<br></div><div><br></div>
<div>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.<br></div></div></div></blockquote><div><br></div></div>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.<div><br></div><div>John.</div></body></html>