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

2024-10-26


1663. Capturing an empty pack expansion

Section: 7.5.6.3  [expr.prim.lambda.capture]     Status: NAD     Submitter: Michael Wong     Date: 2013-04-15

N3690 comment CA 19

The conditions under which a closure class has a conversion function to a pointer-to-function type are given in 7.5.6 [expr.prim.lambda] paragraph 6:

The closure type for a non-generic lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to function...

Does this apply to a lambda whose lambda-capture is empty by virtue of being an empty pack expansion? For example, is the following well-formed?

  #include <cstdlib>

  template <typename ...Args>
  void foo(Args ...args) {
    auto xf = [args ...] { };
    std::atexit(xf);
  }

This is likely a violation of the rule in 13.8 [temp.res] paragraph 8,

If every valid specialization of a variadic template requires an empty template parameter pack, the template is ill-formed, no diagnostic required.

Does this need to be clarified?

Rationale (September, 2013):

The statement in 7.5.6 [expr.prim.lambda] paragraph 6 is a syntactic constraint, not a semantic one. The example has a lambda-capture, regardless of its expansion in a given instantiation. This is consistent with the intent expressed in 13.7.4 [temp.variadic] paragraph 6:

When N is zero, the instantiation of the expansion produces an empty list. Such an instantiation does not alter the syntactic interpretation of the enclosing construct...