I found what seems to be a compiler bug in Visual Studio 2019 (toolset v142). Here's a minimal piece of code to test for yourself:
#include <functional>
#include <vector>
#include <iostream>
int main()
{
auto someLamb = [&]()
{
enum EnumA { eFoo = 0, eBar = 1, eCount = 2 };
enum EnumB { eUndefined = -1, eFirst = 0 };
std::vector<EnumB> edgesChanges;
edgesChanges.push_back(EnumB::eUndefined);
edgesChanges.push_back(EnumB::eUndefined);
auto innerLamb = [&]()
{
int a = edgesChanges[EnumA::eFoo];
int b = EnumB::eFirst;
int c = edgesChanges[EnumA::eBar];
int d = EnumB::eFirst;
return a == b || c == d;
};
std::cout << "Hello World!\n" << innerLamb();
};
someLamb();
}
I get this in the output:
error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'main::
<lambda_82d455ec4380498d1fafa4212566d992>::()::<lambda_02e80f24e36a566682364f879a75c75d>'
message : No constructor could take the source type, or constructor overload resolution was ambiguous
Notice that the lambdas are nested. If the outer lambda is removed, it compiles fine. Am I doing something wrong?