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

2024-04-18


2450. braced-init-list as a template-argument

Section: 13.3  [temp.names]     Status: DRWP     Submitter: Marek Polacek     Date: 2019-01-07

[ Resolved by paper P2308R1 (Template parameter initialization), adopted in November, 2023. ]

Since non-type template parameters can now have class types, it would seem to make sense to allow a braced-init-list as a template-argument, but the grammar does not permit it.

See also issues 2049 and 2459.

Possible resolution:

The resolution also addresses issue 2049.

  1. Change in 7.3.1 [conv.general] paragraph 3 as follows:

    An expression or braced-init-list E can be implicitly converted to a type T if and only if the declaration T t = E; is well-formed, for some invented temporary variable t (9.4 [dcl.init]).
  2. Change in 7.7 [expr.const] paragraph 12 as follows:

    A converted constant expression of type T is an expression or braced-init-list, implicitly converted to type T, where the converted expression is a constant expression and the implicit conversion sequence contains only (12.1 [over.pre])
    • user-defined conversions,
    • ...
  3. Change in 13.3 [temp.names] paragraph 1 as follows:

    template-argument:
      constant-expression
      type-id
      id-expression
      braced-init-list
    
  4. Change in 13.4.2 [temp.arg.type] paragraph 4 as follows:

      template<auto n> struct B { /* ... */ };
      B<5> b1;        // OK, template parameter type is int
      B<'a'> b2;      // OK, template parameter type is char
      B<2.5> b3;      // OK, template parameter type is double
      B<void(0)> b4;  // error: template parameter type cannot be void
      template<int i> struct C { /* ... */ };
      C<{ 42 }> c1; // OK