lundi 28 décembre 2015

Interaction between default arguments and parameter pack (GCC and clang disagree)

I expect the following code to compile:

#include <iostream>

template <class Tag = void, class T = int, class... Args>
void print(T val = T{}, Args... args) {
    std::cout << val << ' ' << sizeof...(args) << std::endl;
}

int main() {
    print();
    print(3.14);
    print(0, 1, 2);
}

While it compiles on GCC 5.2 (C++11) despite the unused-but-set-parameter warnings, clang 3.6 (C++11) gives the following error messages:

main.cpp:4:33: error: missing default argument on parameter 'args'
void print(T val = T{}, Args... args) {
                                ^
main.cpp:11:5: note: in instantiation of function template specialization 'print<void, int, int, int>' requested here
    print(0, 1, 2);
    ^
main.cpp:4:33: error: missing default argument on parameter 'args'
void print(T val = T{}, Args... args) {
                                ^
2 errors generated.

So, who is correct?

Aucun commentaire:

Enregistrer un commentaire