mardi 17 mars 2015

Can parameter pack function arguments be defaulted?


Vote count:

0




This is a point about which gcc 4.9.2 and clang 3.5.2 are in sharp disgreement. The program:



template<typename ...Ts>
int foo(int i = 0, Ts &&... args)
{
return i + sizeof...(Ts);
}

int main()
{
return foo();
}


compiles without comment from gcc (-std=c++11 -Wall -pedantic). Clang says:



error: missing default argument on parameter 'args'


With foo amended to:



template<typename ...Ts>
int foo(int i = 0, Ts &&... args = 0)
{
return i + sizeof...(Ts);
}


clang has no complaints, but gcc says:



error: parameter pack ‘args’ cannot have a default argument


Which compiler is right?



asked 1 min ago







Can parameter pack function arguments be defaulted?

Aucun commentaire:

Enregistrer un commentaire