Skip to content

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

Open
@xmh0511

Description

@xmh0511
Contributor

[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.

Activity

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[/+] on Apr 28, 2022
frederick-vs-ja

frederick-vs-ja commented on Apr 30, 2022

@frederick-vs-ja
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @xmh0511@frederick-vs-ja

        Issue actions

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