首页 文章

clang vs gcc - 空泛型lambda variadic参数包

提问于
浏览
8

我想我发现lambdas和可调用对象之间存在另一个不一致的问题 .

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个提供l(1);

Live example on godbolt.org .

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 bug跟踪器上找不到与此相关的任何内容(虽然没有花太多时间搜索) - 这是gcc错了吗?

1 回答

  • 1

    我已将此问题报告为gcc bug #68071 .

相关问题