1

在 GCC 4.7.2 上(在 cygwin 上,从源代码编译)使用std::async失败

error: invalid use of incomplete type

一些std::__async_sfinae_helper。我不走运,感谢您的帮助。

#include <future>

int main()
{
  std::async([]{});
}

失败了

g++ -Wall -pedantic -std=c++0x    future.cpp   -o future
future.cpp: In function 'int main()':
future.cpp:5:22: error: invalid use of incomplete type 'std::__async_sfinae_helper<main()::<lambda()>, main()::<lambda()> >::type {aka class std::future<void>}'
In file included from future.cpp:1:0:
/usr/local/lib/gcc/i686-pc-cygwin/4.7.2/../../../../include/c++/4.7.2/future:111:11: error: declaration of 'std::__async_sfinae_helper<main()::<lambda()>, main()::<lambda()> >::type {aka class std::future<void>}'
/usr/local/lib/gcc/i686-pc-cygwin/4.7.2/../../../../include/c++/4.7.2/future: At global scope:
/usr/local/lib/gcc/i686-pc-cygwin/4.7.2/../../../../include/c++/4.7.2/future:187:5: error: 'typename std::__async_sfinae_helper<typename std::decay<_Func>::type, _Fn, _Args ...>::type std::async(_Fn&&, _Args&& ...) [with _Fn = main()::<lambda()>; _Args = {}; typename std::__async_sfinae_helper<typename std::decay<_Func>::type, _Fn, _Args ...>::type = std::future<void>]', declared using local type 'main()::<lambda()>', is used but never defined [-fpermissive]
<builtin>: recipe for target `future' failed

版本信息

% g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i686-pc-cygwin/4.7.2/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: ../gcc-4.7.2/configure --enable-languages=c,c++
Thread model: single
gcc version 4.7.2 (GCC)

c++11 std::async 在 mingw 中不起作用并没有帮助,因为我既没有使用 mingw,也没有使用线程模型 win32。

4

0 回答 0