Class type non-type template parameter initialization does not compile

This template-argument

{.a=1, .b=2}

is not allowed according to the grammar for a template-argument which only allows the following constructs:

template-argument:

constant-expression

type-id

id-expression

A brace-init list is not any of the above constructs, it’s actually an initializer and so it cannot be used as a template-argument.

You can be explicit about the type of the object that you use as the template-argument:

Bar<Foo{.a=1, .b=2}> bar;

and this will work, since this is a constant-expression.

Leave a Comment