The following piece of code does compile on gcc-4.7.1:
struct X {};
template <class T = X, typename U>
void f(const U& m) {
}
int main() {
f<>(0);
}
However, this one doesn't:
struct X {};
template <class T = X, typename U>
void f(const U& m) {
auto g = [] () {};
}
int main() {
f<>(0);
}
gcc-4.7.1 complains:
c.cpp: In function 'void f(const U&)':
c.cpp:5:15: error: no default argument for 'U'
So my question is: is putting default parameters before non-default parameters correct in function template? If yes, why doesn't the second one compile? If no, why does the first one compile? How does C++11 standard say about this syntax?