Skip to content

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

@eisenwave

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 }
+    { }

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