Description
[expr.const] p5.14 says
An expression E is a core constant expression unless the evaluation of E, following the rules of the abstract machine ([intro.execution]), would evaluate one of the following:
-[...]
5.14 in a lambda-expression, a reference to this or to a variable with automatic storage duration defined outside that lambda-expression, where the reference would be an odr-use ([basic.def.odr], [expr.prim.lambda]);
Consider this example:
int main(){
const int value = 0;
constexpr int i= [=](){
return (value,0);
}();
}
the variable value
is an odr-use in the lambda-expression. The full-expression of the initialization of i
should be a core constant expression, and evaluating the initialization will evaluate the lambda-expression. However, major implementations accept this example. The correct meaning can only be inferred from the note that follows p5.14. P5.14 is more or less unclear in this context. Using "in" is a bit strange, whether it means "evaluate in" or something else?
From the meaning implied by the note, I think p5.14 might be
In a lambda-expression, an expression
Eo
that potentially references*this
or a variable with automatic storage duration defined outside that lambda-expression odr-uses the referenced entity, whereEo
would be evaluated by a constant expressionCE
to which the lambda-expression is not being evaluated as part of.
Activity
[-][expr.const] p5.14 The rule about lambda-expression is not clear[/-][+][expr.const] p5.14 The rule about lambda-expression in a core constant expression is not clear[/+]frederick-vs-ja commentedon Apr 30, 2022
I believe this rule is talking about "core constant expression in a lambda-expression", not "lambda-expression in a core constant expression". Agree with you on the status that it's not clear.