This is a point about which gcc 4.9.2 and clang 3.5.2 are in sharp
disagreement. 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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…