【发布时间】:2016-01-23 03:49:29
【问题描述】:
我想我发现了另一个 “clang vs gcc” lambda 和可调用对象之间的不一致。
decltype(l)::operator() 应该等价于C::operator(),但是如果在泛型 lambda 中 variadic pack 为空,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&&...) { 返回 x; };
14:注意:模板参数推导/替换失败:
15 : 注意:候选人需要 2 个参数,提供 1 个
l(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);
}
在 gcc 错误跟踪器上找不到与此相关的任何内容(虽然没有花太多时间搜索) - 这里 gcc 错了吗?
【问题讨论】:
-
看起来像一个 gcc 错误。
标签: c++ gcc lambda clang c++14