<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><br clear="all"><br>-- <br>Alexander<br><br>Best regards.
</div>