【发布时间】:2015-08-18 02:32:43
【问题描述】:
我正在使用 clang 3.5.0 和 gcc 版本 4.9.2(都启用了 C++14 选项,尽管可以在 C++11 中完成尾随返回类型)。
以下代码在 g++ 中编译,而不是在 clang++ 中。我的问题是“哪个是正确的?”
#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 报告
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) {
^
【问题讨论】:
-
这是 Clang 中的一个错误,fixed with Clang 3.6
-
啊..谢谢。我的 search-foo 不够好,无法找到这个。
-
检查最新版本的编译器总是一个好主意。 melpon.org/wandbox 非常适合这个目的。
标签: c++ c++11 gcc c++14 clang++