Clang compile error

I was trying to use clang to compile some Qt 5.1.0 code and came across a compile error when including the file QtCore/qabstractitemmodel.h.

Simplyfying the code, I created bar.cpp:

class bar
{
friend int foo(int seed = 0);
};

inline int foo(int seed) { return seed; }

int main()
{
bar bletch;
}

The error I get using clang version 3.4 (trunk 187329) is:

bar.cpp:3:14: error: friend declaration specifying a default argument must be a definition
friend int foo(int seed = 0);
^
bar.cpp:6:12: error: friend declaration specifying a default argument must be the only declaration
inline int foo(int seed) { return seed; }
^
bar.cpp:3:14: note: previous declaration is here
friend int foo(int seed = 0);
^
2 errors generated.

Moving the initializer “seed = 0” from the friend declaration to the inline declaration compiles without problem.

This code compiles fine with clang 3.3 and gcc 4.7.3.

Robert Ankeney

I was trying to use clang to compile some Qt 5.1.0 code and came across a
compile error when including the file QtCore/qabstractitemmodel.h.

[...]

The error I get using clang version 3.4 (trunk 187329) is:

bar.cpp:3:14: error: friend declaration specifying a default argument must
be a definition
  friend int foo(int seed = 0);
             ^

[...]

This code compiles fine with clang 3.3 and gcc 4.7.3.

Hi,

clang is correct, Qt was wrong.

Previous version of clang or gcc just did not report the error as the C++
standard mandate.

Qt has been already fixed: https://codereview.qt-project.org/60150