Referencing local variable before assignment results in unexpected behavior

C++ lambda can also be used as both closures and immutable inner functions (and also even more options) Lambda expressions (since C++11) - cppreference.com