以下代码段无法使用clang
进行编译,但使用g++
进行编译(详情如下):
#include <utility>
struct S {
template<typename T>
void operator()(T&& /*t*/) {}
template<typename T0, typename T1, typename... Args>
auto operator()(T0&& t0, T1&& /*t1*/, Args&&... args) ->
decltype(operator()(std::forward<T0>(t0), std::forward<Args>(args)...))
{}
};
int main(int /*argc*/, char** /*argv[]*/) {
S()(1, 2);
S()(1, 1.2, 1.2); // does not compile with clang
}
即。可变参数operator()
应该递归,直到达到基本情况。
当我用gcc 7.2.0
(g++ -std=c++1y
)编译它时,它会编译。但是使用clang 3.8.0
(clang++ -std=c++1y
),我获得了以下编译失败:
main.cpp:15:5: error: no matching function for call to object of type 'S'
S()(1, 1.2, 1.2); // does not compile with clang
^~~
main.cpp:8:10: note: candidate template ignored: substitution failure [with T0 = int, T1 = double, Args = <double>]: no matching member function for call to 'operator()'
auto operator()(T0&& t0, T1&& /*t1*/, Args&&... args) ->
^
main.cpp:5:7: note: candidate function template not viable: requires 1 argument, but 3 were provided
void operator()(T&& /*t*/) {}
这是其中一个编译器中的错误还是我可能在某个地方遇到未定义的行为?