Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 558
Vittorio Romeo Avatar asked Nov 11 '16 21:11

Vittorio Romeo


1 Answers

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.

like image 146
T.C. Avatar answered Sep 19 '22 04:09

T.C.