Vittorio Romeo Vittorio Romeo - 1 year ago 82
C++ Question

Is "template argument deduction for class templates" supposed to deduce empty parameter packs for variadic class templates?

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?

Answer Source


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-seqopt initializer

The initializer is not optional.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download