Tuesday, 15 July 2014

c++ - Can parameter pack function arguments be defaulted? -


This is a point about which the gcc 4.9.2 and 3.5.5 clamps are in sharp disagreement. Program:

  template & lt; Typename ... Ts & gt; Int foo (int i = 0, ts & amp; args) {return i + sizeof ... (ts); } Int main () {return foo (); }  

compiled without comment from GCC ( -std = c + + 11 -Wall -pedantic ) Clang says:

  Error: The default argument on the parameter 'args' is not to modify  foo  with  

  Template & lt; Typename ... Ts & gt; Int foo (int i = 0, ts & ... args = 0) {return i + sizeof ... (ts); }  

There is no complaint for the clang, but the GCC says:

  Error: parameter pack 'Args' can not have any default arguments  

Which compiler is correct?

from 8.3.6 ([dcl.fct.default]) / 3:

No default argument will be specified for blockquote>

parameter pack.

From 8.3.6 ([dcl.fct.default]) / 4:

In a given function declaration, one with a default argument After the parameter, each parameter will have a default argument given in this or previous declaration or a function parameter pack.

Therefore it allows code like void f (int a = 10, args ... args) , or actually like your first snippet ( Thanks to @Tc to see the second sentence!)


No comments:

Post a Comment