Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expr.const] p5.14 The rule about lambda-expression in a core constant expression is not clear #5423

Open
xmh0511 opened this issue Apr 28, 2022 · 1 comment

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Apr 28, 2022

[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, where Eo would be evaluated by a constant expression CE to which the lambda-expression is not being evaluated as part of.

@xmh0511 xmh0511 changed the title [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 Apr 28, 2022
@frederick-vs-ja
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants