[expr.const] p5.14 The rule about lambda-expression in a core constant expression is not clear
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
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
Eothat potentially references*thisor a variable with automatic storage duration defined outside that lambda-expression odr-uses the referenced entity, whereEowould be evaluated by a constant expressionCEto which the lambda-expression is not being evaluated as part of.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with [expr.const] p5.14 and the note that follows it, then compare their wording with the lambda example in the issue. Clarify what “in a lambda-expression” means and ensure the revised rule consistently explains whether the example is a core constant expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100