cplusplus / cplusplus/draft

[expr.prim.lambda.capture] Question about the example in p9

Open
#1,621 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cwg not-editorial
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

This is the example in [expr.prim.lambda.capture]p9:

void f2() {
  int i = 1;
  void g1(int = ([i]{ return i; })()); // ill-formed
  void g2(int = ([i]{ return 0; })()); // ill-formed
  void g3(int = ([=]{ return i; })()); // ill-formed
  void g4(int = ([=]{ return 0; })()); // OK
  void g5(int = ([]{ return sizeof i; })()); // OK
}

My question is, what is the smallest enclosing scope of the lambdas in this example?

According to my understanding, it is the function prototype scope. But then the declaration of g4 is not OK: the smallest enclosing scope of the lambda is not a block scope, and so according to [expr.prim.lambda.capture]p3 no capture-default is allowed.

Note that CWG 1632 is also about [expr.prim.lambda.capture]p3 (previously [expr.prim.lambda]p9).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading [expr.prim.lambda.capture] paragraphs 3 and 9, then compare the example with the interpretation described in CWG 1632. Determine whether the stated status of g4 is consistent with the smallest-enclosing-scope rule; done means resolving the question or identifying the required standard wording change.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.