I discovered that gcc and clang allow to use decltype(auto)
in non-type template parameter type clause. E.g.:
template <decltype(auto)>
struct X {};
int foo ;
int main() {
X<(foo)> x;
static_cast<void>(x);
}
[live demo gcc] [live demo clang]
Is it standard compliant feature or is it some gnu extension?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With