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.
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/VgYjCk
Any answers as to whether this should work or not as well as any workarounds are appreciated.
Thank you.
Aucun commentaire:
Enregistrer un commentaire