Skip to content

CWG3061 [stmt.expand] Trailing commas in an expansion-init-list should be permitted #754

Description

@eisenwave

Reference (section label): [stmt.expand]

Issue description

         for (int x : { 1, }) { } // OK
template for (int x : { 1, }) { } // syntax error

Unlike any other brace-enclosed list, an expression-list in an expansion-init-list does not permit the use of trailing commas. This is almost certainly a cplusplus/papers#156 oversight given obvious inconsistencies and that the paper does not discuss this as a design choice.

Furthermore, existing implementations of expansion statements do not implement the standard behavior; see https://godbolt.org/z/czYqPG3r6.

Suggested resolution

Change the syntax of expansion-init-list as follows:

 expansion-init-list:
-    { expression-list opt }
+    { expression-list , opt }
+    { }

Activity

  1. changed the title [-][stmt.expand] Trailing commas in an *expansion-init-list* should be permitted[/-] [+][stmt.expand] Trailing commas in an expansion-init-list should be permitted[/+] on Aug 24, 2025
  2. jensmaurer commented on Sep 12, 2025

    @jensmaurer
    Member
  3. changed the title [-][stmt.expand] Trailing commas in an expansion-init-list should be permitted[/-] [+]CWG3061 [stmt.expand] Trailing commas in an expansion-init-list should be permitted[/+] on Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions