15
template <typename... Args>
void bark( int = 0, Args&&... args ) {}

int main() {
     bark();
     bark(1);
     bark(1, 2);
}

Is this code well-formed according to the C++ Standard?

The proposed duplicate does not contain the same calls of the function.

Puppy
  • 144,682
  • 38
  • 256
  • 465
  • 1
    Not a duplicate: http://stackoverflow.com/questions/29098835/can-parameter-pack-function-arguments-be-defaulted, doesn't contain calls of the same form. – Puppy Feb 25 '16 at 22:57
  • Looks like a duplicate to me. Even if the invocation isn't identical, the answer in that question shows the two parts of the standard that say it's not valid even in this case. – Kurt Stutsman Feb 25 '16 at 23:00
  • 1
    The issue raised in that question has been fixed in Clang, but Clang still rejects this code. – Puppy Feb 25 '16 at 23:03
  • Hmm I misread the standard snippet in the answer there. It actually _is_ supposed to be valid code according to the standard. It's still a duplicate though. Your form is identical to the first part of that question. – Kurt Stutsman Feb 25 '16 at 23:06
  • I am still confused on why this is not a dupe. The other question answers this. – NathanOliver Feb 26 '16 at 00:17
  • Like I said, the other question doesn't contain the same calls of the function. – Puppy Feb 26 '16 at 08:48

1 Answers1

14

Due to CWG 777, the declaration is valid:

In a given function declaration, all each parameters subsequent to a parameter with a default argument shall have a default arguments supplied in this or a previous declarations or shall be a function parameter pack.

Deduction should succeed in all three cases, since the default argument makes no difference to the nature of deduction: If no argument to the pack parameter args is provided, it's deduced to the empty pack via [temp.arg.explicit]/3, otherwise the usual rule in [temp.deduct.call]/1 applies (as the pack is clearly not in a non-deduced context).

Columbo
  • 60,038
  • 8
  • 155
  • 203