int x = 100;
int& f() { return x; }
auto g = []() mutable -> int& { return x; };
std::function<int&()> funcfunc()
{
std::cin >> x;
int& (&h)() = x > 0 ? f : g;
return h;
}
Somehow it compiles with MSVC
, while clang
and gcc
believe g could not convert to int&(*)() and then be used to initialize h with type 'int&(&)()'