This question is related to this one.
Why doesn't this compile:
int main() {
auto foo = [&]() -> int {foo; return {};}();
(void)(foo);
}
Error:
main.cpp: In lambda function:
main.cpp:3:30: error: use of 'foo' before deduction of 'auto'
auto foo = [&]() -> int {foo; return {};}();
^~~
But casting foo to the resulting type allows compilation:
int main() {
auto foo = [&]() -> int {int(foo); (void)(foo);return {};}();
(void)(foo);
}