Vit*_*meo 8 c++ lambda gcc clang c++14
我想我发现lambdas和可调用对象之间的另一个"clang vs gcc"不一致.
decltype(l)::operator()
应该等效于C::operator()
,但如果variadic pack在泛型lambda中保留为空,则gcc拒绝编译:
15:错误:对'(main()::)(int)'l(1)的调用不匹配;
15:注意:候选人:decltype(((main()::) 0u).main()::(x,))(*)(auto:1 &&,auto:2 &&,...)
15:注意:候选人需要3个参数,2个提供
14:注意:候选人:模板main()::
auto l = [](auto && x,auto && ...){return x; };
14:注意:模板参数扣除/替换失败:
15:注意:候选人需要2个参数,1个提供
升(1);
struct C
{
template<typename T, typename... TRest>
auto operator()(T&& x, TRest&&...){ return x; }
};
int main()
{
// Compiles both with clang and gcc.
auto c = C{};
c(1);
// Compiles with clang 3.7.
// Does not compile with gcc 5.2.
auto l = [](auto&& x, auto&&...) { return x; };
l(1);
}
Run Code Online (Sandbox Code Playgroud)
在gcc bug跟踪器上找不到与此相关的任何内容(虽然没有花太多时间搜索) - 这是gcc错了吗?