Consider the following code:
int main() {
void(*ptr)() noexcept = []() noexcept {
// ...
};
}
It compiles with gcc/clang but it fails to compile with msvc.
The error is quite obscure:
error C2440: 'initializing': cannot convert from 'main::' to 'void (__cdecl *)(void) noexcept'
note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Everything works fine if I remove the noexcept
as it follows:
int main() {
void(*ptr)() = []() noexcept {
// ...
};
}
As far as I can see, the code is correct and msvc should accept it as well as gcc and clang. Is there something wrong in the snippet or is it a bug of msvc?