Title
Expanding packs created within a pack expansion
Status
ready
Section
13.7.4 [temp.variadic]
Submitter
Jay Ghiron

Created on 2026-08-16.00:00:00 last changed 2 weeks ago

Messages

Date: 2026-11-19.20:46:27

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]
Date: 2026-11-19.16:44:01

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]
Date: 2026-08-16.00:00:00

(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.

History
Date User Action Args
2026-11-19 20:46:27adminsetstatus: tentatively ready -> ready
2026-11-19 16:44:01adminsetmessages: + msg8720
2026-09-03 23:06:47adminsetstatus: open -> tentatively ready
2026-08-16 10:40:15adminsetmessages: + msg8648
2026-08-16 00:00:00admincreate