The "Template argument deduction for class templates" proposal (P0091R2) contains the following example:
template<class ... Ts> struct X { X(Ts...) };
X x1{1}; // OK X<int>
X x11; // OK X<>
(Apart from the fact that the constructor definition is missing a body), the example seems to suggest that a variadic class template constructed with zero argument will be deduced with an empty parameter pack.
Unfortunately, the latest version of g++ does not agree:
int main()
{
X x1{1};
X x11;
}
In function 'int main()':
error: invalid use of template-name 'X' without an argument list
X x11;
^
note: class template argument deduction requires an initializer
example on wandbox
I could not find explicit wording in the proposal that clarifies this interaction. Is g++ wrong here?
This is now well-formed after P0620R0 removed the cited restriction right before C++17's publication.
Previous answer kept for reference:
N4618 [dcl.type.class.deduct]/1:
If a placeholder for a deduced class type appears as a decl-specifier in the decl-specifier-seq of a simple-declaration, the init-declarator of that declaration shall be of the form
declarator-id attribute-specifier-seqoptinitializer
The initializer is not optional.
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