I was playing around with IIFE's and parameter packs in MSVC C++20 when I stumbled across a strange error. The following code is a minimal reproducible example.
#include <functional>
#include <iostream>
template <typename... Ts>
struct Foo {
std::function<void(Ts...)> fnc = {};
Foo() {}
Foo(const Foo&) : fnc(
[](Ts... ts) {
bool test = ([&ts](){ return true; }() && ...);
std::cout << test << std::endl;
}
) {}
};
int main() {
Foo<int> f;
Foo<int> f2 = f;
return 0;
}
This gives the following error(s):
error C4700 uninitialized local variable 'test' used
fatal error LNK1257: code generation failed
which does not make sense to me. What's even more strange is that making the copy constructor a default constructor gets rid of the error. Should this be the case, or is there a bug in the compiler?