<div dir="ltr">This is taken from clang source at the point where the error is emitted:<div><br></div><div><div>// C++11 [dcl.fct.default]p4: If a friend declaration specifies a</div><div>// default argument expression, that declaration shall be a definition</div>

<div>// and shall be the only declaration of the function or function</div><div>// template in the translation unit.</div></div><div><br></div><div>Not sure how wide spread this construct is, I'm seeing it for the first time. The code is not hard to fix and error seems appropriate to me.</div>

</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 23, 2014 at 9:48 PM, Александр Овчинников <span dir="ltr"><<a href="mailto:sanek23994@gmail.com" target="_blank">sanek23994@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<br>In the <a href="http://clang.debian.net/" target="_blank">http://clang.debian.net/</a>
 project Sylvestre, Arthur and I are trying to rebuild Debian with 
clang. And we have the problems with default arguments in the friend 
methods. (<a href="http://clang.debian.net/status.php?version=3.4.2&key=WRONG_DEFAULT_DECLARATION" target="_blank">http://clang.debian.net/status.php?version=3.4.2&key=WRONG_DEFAULT_DECLARATION</a>). This issue affects 19 packages in the Debian rebuild.<br>




<br>In the process of the rebuild Debian packages we had created simple 
example which contains different behavior with gcc and clang. 
Please see below:<br><br><b>Simple example </b><br><div>
int func1(int i, int j) { return i + j; }<br></div>
<br>class foo {<br>friend int func1(int i, int j = 0);<br>public:<br>    int func();<br>};<br><br>int foo::func() { return func1(1); }<br><br>int main() {<br>    foo a;<br>    a.func();<br>    return 0;<br>
}<br><br>Clang compilation error: <br>test.cpp:8:12: error: friend declaration specifying a default argument must be the only declaration<br>friend int func1(int i, int j = 0);<br>
           ^<br>test.cpp:1:5: note: previous declaration is here<br><div>int func1(int i, int j)<br>    ^<br></div>test.cpp:15:12: error: no matching function for call to 'func1'<br>    return func1(1);<br>
           ^~~~~<br>
test.cpp:1:5: note: candidate function not viable: requires 2 arguments, but 1 was provided<div><br>int func1(int i, int j)<br>    ^<br></div>2 errors generated.<br><div><br></div><div>The
 provided example successfully complies by gcc. So as it seems for the 
clang successfully compilation failed packages requires patches.<br>

</div><div>As I understand the following code is correct way to using default arguments with friend functions:<br><br>int func1(int i, int j = 0);<br><br>class foo {<br>friend int func1(int i, int j);<br><div>
public:<br>    int func();<br>};<br><br>int foo::func()
{ return func1(1); }<br><br>int main() {<br>    foo a;<br>    a.func();<br>    return 0;<br>}<br><br></div><div>int func1(int i, int j) { return i + j; }<br><br></div>Even if clang seems to follow the C++ specification, I wonder if clang
is not too strict here.<br>
For example, this patch, to make sure that the code compiles with clang, I had to basically get ride of the default feature:<br>
<a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=gfan.diff;att=1;bug=755308" target="_blank">https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=gfan.diff;att=1;bug=755308</a><br>
to be able to compile the code with clang without touching the API.</div><span class="HOEnZb"><font color="#888888"><br clear="all"><br>-- <br>Alexander<br><br>Best regards.
</font></span></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>