Clause / Subclause / Annex:
5.1.1
Para/Table/Figure:
12
Comment type:
Te
Comment / justification for change:
“If one or more names in the effective capture set are preceded by &, the effect of invoking a closure object or a copy after the innermost block scope of the context of the lambda expression has been exited is undefined.”
That is too restrictive. The behaviour should be undefined iff the lifetime of any of the variables referenced has ended.
This should be safe and legal; currently it has undefined behaviour:
int i;
reference_closure
if (blah) { f = [&i]() { }; }
if (f) f();
Recommended change:
“If one or more names in the effective capture set are preceded by &, the effect of invoking a closure object or a copy after the lifetime of any of the variables referenced has ended is undefined.”
MB:
UK
I like the fact we are
I like the fact we are deferring the problem to another well-defined part of the standard that deals with variable lifetime. This avoids risks of redundancy and contradiction.
I want to check that the term ‘lifetime has ended’ is well defined, or see if there are more core-friendly ways of saying this. First impression is that this is indeed the correct wording though.
I believe this is the
I believe this is the correct terminology – see 3.8/1 et seq.
I suspect we could just delete the paragraph and we’d be ok – but there’s no harm in restating the rule here.