使用__compressed_pa​​ir时出错

时间:2013-05-06 10:57:03

标签: c++ c++11 clang libc++

我开始在 libc ++ master之上实现N3558(请参阅future here),但我现在遇到functional中的错误,我不明白。

无论我如何对其进行编码,它始终会因__compressed_pair错误而失败。我不知道我是否遗漏了某些内容,或者这是libc++中的错误。

以下代码:

#include <future>

struct test {
    test() {
        int someint = 0;
        std::promise<void> prom;
        auto fut = prom.get_future();
        fut.then( [this, someint]( std::future<void> future ) {
        } );
    }
};
clang 3.3 中的

触发器:

In file included from /std/include/map:375:
/std/include/functional:993:11: error: no matching constructor for initialization of '__compressed_pair<<lambda at          /std/include/future:1096:14>, std::__1::allocator<<lambda at    /std/include/future:1096:14> > >'
    : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
      ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/std/include/functional:1278:26: note: in instantiation of member function 'std::__1::__function::__func<<lambda at /std/include/future:1096:14>, std::__1::allocator<<lambda at /std/include/future:1096:14> >, void ()>::__func' requested here
        ::new (__f_) _FF(_VSTD::move(__f));
                     ^
/std/include/__functional_base:341:37: note: in instantiation of function template specialization 'std::__1::function<void ()>::function<<lambda at /std/include/future:1096:14> >' requested here
return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...);
                                ^
/std/include/__config:301:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
          ^
/std/include/functional:1691:12: note: in instantiation of function template specialization 'std::__1::__invoke<const <lambda at /std/include/future:1144:17> &, const <lambda at /std/include/future:1096:14> &>' requested here
return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
       ^
/std/include/functional:1761:20: note: in instantiation of function template specialization 'std::__1::__apply_functor<const <lambda at /std/include/future:1144:17>, const std::__1::tuple<<lambda at /std/include/future:1096:14> >, 0, std::__1::tuple<> >' requested here
        return __apply_functor(__f_, __bound_args_, __indices(),
               ^
/std/include/future:1114:3: note: in instantiation of function template specialization 'std::__1::__bind<<lambda at /std/include/future:1144:17>, <lambda at /std/include/future:1096:14> >::operator()<>' requested here
            invoke_bind();
            ^
/std/include/future:1148:22: note: in instantiation of function template specialization 'std::__1::__then<void>::bind<std::__1::future<void>, <lambda at game/Game_local.cpp:1020:9>, <lambda at /std/include/future:1144:17> >' requested here
    return __then<_Rp>::bind( fut, forward<F>(execute_func), move(invoker) );
                        ^
/std/include/future:1527:34: note: in instantiation of function template specialization 'std::__1::__then<void>::bind_async<std::__1::future<void>, <lambda at game/Game_local.cpp:1020:9> >' requested here
{return __then<return_type>::bind_async( *this, std::forward<Function>(func) );}
                             ^
game/local.cpp:1020:3: note: in instantiation of function template specialization 'std::__1::future<void>::then<<lambda at game/Game_local.cpp:1020:9> >' requested here
    .then( [this, someint]( std::future<void> future ) {
     ^
/std/include/memory:2371:31: note: candidate constructor not viable: requires 0 arguments, but 3 were provided
_LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
                          ^
/std/include/memory:2372:40: note: candidate constructor not viable: requires single argument '__t1', but 3 arguments were provided
_LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
                                   ^
/std/include/memory:2374:40: note: candidate constructor not viable: requires single argument '__t2', but 3 arguments were provided
_LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
                                   ^
/std/include/memory:2376:31: note: candidate constructor not viable: requires 2 arguments, but 3 were provided
_LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
                          ^
/std/include/memory:2357:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 3 were provided
class __compressed_pair
  ^
/std/include/memory:2357:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 3 were provided

使用 gcc 4.8 进行编译会产生更加错误的错误消息,但它基本相同。

有人可以解释一下吗?

1 个答案:

答案 0 :(得分:2)

基本上,当你尝试从bind_async(future:1144)调用invoker的绑定时,会发生有趣的部分。这个lambda将std :: function作为参数,但你的绑定在那里有一个lambda。所以它从lambda构造参数,它在内部创建类型擦除子类_ function :: _func。 __func存储lambda和allocator,并且为了在使用无状态分配器时不浪费空间,它使用__compressed_pa​​ir。因此它尝试使用piecewise_construct构造函数构造compressed_pa​​ir,但未能找到它。

为什么找不到?有问题的构造函数(在内存中:2416)位于#if块下,特别是

#ifndef _LIBCPP_HAS_NO_VARIADICS

所以我要假设这个符号在你的构建中被定义了。你是否将-std = c ++ 11传递给你的编译器?如果是(以及其他所有东西会如何编译?),也许你需要仔细检查libc ++的配置。在任何情况下,您都应该尝试在上面的预处理器块中添加#else并在其中放置#error,以确保这确实是您遇到的问题。