This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-01-15


1662. Capturing function parameter packs

Section: 7.5.5.3  [expr.prim.lambda.capture]     Status: C++14     Submitter: Michael Wong     Date: 2013-04-15

N3690 comment CA 20

[Moved to DR at the February, 2014 meeting.]

The example in 7.5.5 [expr.prim.lambda] paragraph 24 reads,

  template<class... Args>
  void f(Args... args) {
    auto lm = [&, args...] { return g(args...); };
    lm();
  }

However, it's not clear how this example squares with the requirements in paragraph 10,

The identifier in a simple-capture is looked up using the usual rules for unqualified name lookup (6.5.3 [basic.lookup.unqual]); each such lookup shall find a variable with automatic storage duration declared in the reaching scope of the local lambda expression.

since a function parameter pack is not a variable. Although the requirement might be met in a given specialization of the function template, is there a rule that relaxes it in the context of the function template definition?

Proposed resolution (September, 2013):

  1. Change 7.5.5 [expr.prim.lambda] paragraph 10 as follows:

  2. The identifier in a simple-capture is looked up using the usual rules for unqualified name lookup (6.5.3 [basic.lookup.unqual]); each such lookup shall find an entity. An entity that is designated by a simple-capture is said to be explicitly captured, and shall be this or a variable with automatic storage duration declared in the reaching scope of the local lambda expression. An entity (i.e. a variable or this) is said to be explicitly captured if it is found by this process.
  3. Change 13.7.4 [temp.variadic] paragraph 4 as follows:

  4. ...Pack expansions can occur in the following contexts:

    For the purpose of determining whether a parameter pack satisfies a rule regarding entities other than parameter packs, the parameter pack is considered to be the entity that would result from an instantiation of the pattern in which it appears.

    [Example:

    ...
  5. Change 13.7.4 [temp.variadic] paragraph 6 as follows:

  6. ...Each Ei is generated by instantiating the pattern and replacing each pack expansion parameter with its ith element. Such an element, in the context of the instantiation, is interpreted as follows:

    All of the Ei become elements in the enclosing list. [Note:...