确认:您的代码在这里产生同样的问题:
编译器:g++ -v
给出
Using built-in specs.
COLLECT_GCC=/opt/local/bin/g++-mp-4.8
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.8.1/lto-wrapper
Target: x86_64-apple-darwin12
配置为:../gcc-4.8-20130328/configure --prefix=/opt/local --build=x86_64-apple-darwin12 --enable-languages=c,c++,objc,obj-c++,fortran,java - -libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir =/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.8 --with-gxx -include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with- ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable- lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc48 4.8-20130328_0'
Thread model: posix
gcc version 4.8.1 20130328 (prerelease) (MacPorts gcc48 4.8-20130328_0)
在 gdb 中运行它会给出:
doing the test
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x0000000100081c30 in __once_proxy ()
(gdb) up
#1 0x00007fff8872fff0 in pthread_once ()
(gdb) up
#2 0x0000000100000fd2 in __gthread_once ()
(gdb) up
#3 0x00000001000020c9 in _ZSt9call_onceIMNSt13__future_base11_State_baseEFvRSt8functionIFSt10unique_ptrINS0_12_Result_baseENS4_8_DeleterEEvEERbEIKPS1_St17reference_wrapperIS8_ESF_IbEEEvRSt9once_flagOT_DpOT0_ ()
(gdb) up
#4 0x0000000100001886 in std::__future_base::_State_base::_M_set_result ()
(gdb) up
#5 0x00000001000025ef in std::promise<bool>::set_value ()
(gdb) up
#6 0x000000010000119f in main ()
所以这似乎是 libstdc++ 中的一些错误。顺便说一句,使用 clang 3.2(自制软件),它编译和运行良好(result is 1
)。也许您应该使用 bugzilla 提交错误报告...