This is a follow up of the discussion found here.
The following code compiles both under gcc and clang (live demo). This is surprising for the case in line //1
The difference is the (lack of) evaluation of context. sizeof is unevaluated.
As per N3337 (≈C++11)
§5.1 2 [expr.prim.lambda] / 11
If a lambda-expression has an associated capture-default and its compound-statement odr-uses
thisor a variable with automatic storage duration and the odr-used entity is not explicitly captured, then the odr-used entity is said to be implicitly captured;
and
§5.1.2 [expr.prim.lambda] / 12
If a lambda-expression odr-uses
thisor a variable with automatic storage duration from its reaching scope, that entity shall be captured by thelambda-expression. If a lambda-expression captures an entity and that entity is not defined or captured in the immediately enclosing lambda expression or function, the program is ill-formed.
ODR use means use in potentially evaluated context:
§3.2 [basic.def.odr] / 2
An expression is potentially evaluated unless it is an unevaluated operand or a subexpression thereof. A variable whose name appears as a potentially-evaluated expression is odr-used unless it is an object that satisfies the requirements for appearing in a constant expression and the lvalue-to-rvalue conversion is immediately applied
Since sizeof isn't, and s is in reaching scope of the lambda expression, it is okay. Returning s means evaluating it, though, and that's why it's ill-formed.