mercredi 3 juin 2015

C++14 variadic template argument inference in clang and gcc

I am using clang 3.5.0 and gcc version 4.9.2 (both with C++14 options on, although with trailing return types this could be done in C++11).

The following code compiles in g++ and not in clang++. My question is "which is right?"

#include <iostream>
#include <tuple>
#include <functional>
using namespace std;

template<typename OP, typename F1, typename... Fs>
struct symop {
     OP op;
     tuple<F1,Fs...> fs;

     symop(const OP &oopp, const F1 &f1, const Fs &...ffss)
          : op(oopp), fs(f1,ffss...) {}
};

template<typename OP, typename... Fs>
auto baz(const symop<OP,Fs...> &so) {
     return so.op(get<0>(so.fs),get<1>(so.fs));
}

/* // this version compiles on both compilers
template<typename OP, typename F1, typename... Fs>
auto baz(const symop<OP,F1,Fs...> &so) {
     return so.op(get<0>(so.fs),get<1>(so.fs));
}
*/

int main() {
     symop<plus<int>,int,int> so{plus<int>{},3,4};
     cout << baz(so) << endl;
}

Clang reports

q.cpp:29:10: error: no matching function for call to 'baz'
        cout << baz(so) << endl;
                ^~~
q.cpp:16:6: note: candidate template ignored: couldn't infer template argument
      'OP'
auto baz(const symop<OP,Fs...> &so) {
     ^

Aucun commentaire:

Enregistrer un commentaire