c++ - C++14 variadic template argument inference in clang and gcc -
i using clang 3.5.0 , gcc version 4.9.2 (both c++14 options on, although trailing return types done in c++11).
the following code compiles in g++ , not in clang++. question "which 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)); } /* // 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 call '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) { ^
you should understand clang still experimental (even though "widely" used), , built upon gcc (trough has significant changes) , can sure (talking c++ code) compiled in gcc should compile in clang, , if not, clang bug.
gcc had it's time prove being robust.
Comments
Post a Comment