Can non-type template parameters in c++17 be decltype(auto)?

This is standard. First, for a non-type template parameter:

[temp.param/4]

A non-type template-parameter shall have one of the following
(optionally cv-qualified) types:

  • a type that contains a placeholder type.

Where placeholder types have the following specified:

[dcl.spec.auto/1]

The auto and decltype(auto) type-specifiers are used to designate a
placeholder type
that will be replaced later by deduction from an
initializer. The auto type-specifier is also used to introduce a
function type having a trailing-return-type or to signify that a
lambda is a generic lambda ([expr.prim.lambda.closure]). The auto
type-specifier is also used to introduce a structured binding
declaration.

[dcl.spec.auto/5]

A placeholder type can also be used in the type-specifier-seq in the
new-type-id or type-id of a new-expression and as a decl-specifier of
the parameter-declaration’s decl-specifier-seq in a
template-parameter.

Since the bullet above says “placeholder type”, and such a type can be designated either with auto or decltype(auto), both compilers are correct.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)