Lambda expressions may capture objects with automatic storage duration from the set of enclosing scopes (called the reaching scope) for use in the lambda's function body. These captures may be either be explicit, by specifying the object to capture in the lambdas lambda's capture-list, or implicit, by using a capture-default and referring to the object within the lambda's function body. When capturing an object, explicitly or implicitly, that object is either captured by copy or captured by reference. When an object is captured by copy, the lambda object will contain an unnamed nonstatic data member that is initialized to the value of the object being captured. This nonstatic data member's lifetime is that of the lambda object's lifetime. However, when an object is captured by reference, the lifetime of the referent is not tied to the lifetime of the lambda object.
...
When a lambda object outlives one of its reference-captured objects, execution of the lambda object's function call operator results in undefined behavior once that reference-captured object is accessed. Therefore, a lambda object must not outlive any of its reference-captured objects. This is a specific instance of EXP54-CPP. Do not access an object outside of its lifetime.
...
[ISO/IEC 14882-2014] | Subclause 3.8, "Object Lifetime" Subclause 5.1.2, "Lambda Expressions" |
...