3

我开始在libc++ master之上实现N3558 (请参见此处),但现在我遇到了一个错误,我不明白。future 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编译会给出更难看的错误消息,但基本相同。

任何人都可以解释一下吗?

4

1 回答 1

3

基本上,有趣的部分发生在您尝试从bind_async(future:1144) 调用调用程序的绑定时。此 lambda 以 astd::function作为参数,但您的绑定在那里有一个 lambda。所以它从 lambda 构造参数,它在内部创建类型擦除子类__function::__func__func同时存储 lambda 和分配器,为了在使用无状态分配器时不浪费空间,它使用__compressed_pair. 因此,它尝试使用分段构造构造函数构造压缩对,但找不到。

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

#ifndef _LIBCPP_HAS_NO_VARIADICS

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

于 2013-05-06T11:42:47.273 回答