In the code below, on the first form, gcc complains about having a lambda in a template parameter. In the second form, gcc complains about lambda_function_pointer not having external linkage. Clang compiles and runs the code just fine even with -pedantic.
The +
in front of the lambda is to coerce it to decay into a function pointer.
template<auto f>
void func() {
f();
}
void g();
int main() {
func<+[](){}>(); // gcc complains about lambda in template args
constexpr auto lambda_function_pointer = +[](){};
func<lambda_function_pointer>(); // gcc complains about not having external linkage
}
live: https://godbolt.org/g/ey5uo7
Thank you.
edit: https://timsong-cpp.github.io/cppwp/n4659/expr.prim.lambda#2
mentions lambdas not appearing in template parameters for the sake of the lambda not being in the signature, but with the +
, it gets rid of the lambda type.
edit2: This may be relevant for the linkage portion of the question: Why did C++03 require template parameters to have external linkage?