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

2026-11-21


3218. Expanding packs created within a pack expansion

Section: 13.7.4  [temp.variadic]     Status: ready     Submitter: Jay Ghiron     Date: 2026-08-16

(From submission #976.)

Consider:

   struct S {};

   int f(auto ... x) {
     int a[] = { [&] {
       auto[...y] = x;
       return y;    // #1
     }()...};       // #2
     return 0;
   }
   int x = f(S());

The use of y at #1 should be ill-formed due to the appearance of an unexpanded pack. The expansion at #2 should not apply to y. Some implementations fail spectacularly.

Proposed resolution (approved by CWG 2026-09-01) [SUPERSEDED]:

Change in 13.7.4 [temp.variadic] paragraph 8 as follows:

A pack whose name appears within the pattern of a pack expansion is expanded by that pack expansion if unqualified name lookup (6.5.3 [basic.lookup.unqual]) from the point of the pack expansion finds a declaration of that pack. An appearance of the name of a pack is only expanded by the innermost enclosing pack expansion. The pattern of a pack expansion shall name one or more packs that are not expanded by a nested pack expansion; such packs are called unexpanded packs in the pattern. All of the packs expanded by a pack expansion shall have the same number of arguments specified. An appearance of a name of a pack that is not expanded is ill-formed. [Example: ...
  int h(auto) {
    ([](auto ...xs){ xs; }, ...);   // error: unexpanded pack
  }
-- end example]

Proposed resolution (approved by CWG 2026-11-19):

Change in 13.7.4 [temp.variadic] paragraph 8 as follows:

A pack whose name appears within the pattern of a pack expansion is expanded by that pack expansion if the target scope of the declaration of the pack contains the point of the pack expansion. An appearance of the name of a pack is only expanded by the innermost enclosing pack expansion. The pattern of a pack expansion shall name one or more packs that are not expanded by a nested pack expansion; such packs are called unexpanded packs in the pattern. All of the packs expanded by a pack expansion shall have the same number of arguments specified. An appearance of a name of a pack that is not expanded is ill-formed. [Example: ...
  int h(auto) {
    ([](auto ...xs){ xs; }, ...);   // error: unexpanded pack
  }
-- end example]