libc++的一个错误?未来和C++11
A bug for libc++ ? future and C++11
#include <thread>
#include <future>
#include <iostream>
#include <atomic>
#include <cstdint>
template <typename T>
void consumeFuture(std::future<T>&& fut) {
fut.get();
}
template <typename T>
void actOnT(std::atomic<T>& at) {
++at;
}
int main() {
std::atomic<uint32_t> a{42};
consumeFuture(std::async(std::launch::async, &actOnT<uint32_t>, std::ref(a)));
std::cout << a << "n";
}
这段代码在 Ubuntu 13.10 64 位下编译得很好,带有g++ 4.8.1
和libstdc++
,它无法在与clang
和libc++
相同的平台上编译,因为libc++
库显然没有以正确的方式实现所有内容。
这是 clang 的 c++ 标准库的错误还是我的代码有问题?
我正在使用官方 llvm apt 存储库中libc++
和libc++abi
的1.0~svn181765-1
版本。
使用clang++
libc++
获得的输出:
In file included from future_1.cpp:1:
In file included from /usr/bin/../include/c++/v1/thread:90:
In file included from /usr/bin/../include/c++/v1/__functional_base:15:
/usr/bin/../include/c++/v1/type_traits:2761:19: error: invalid application of 'sizeof' to an incomplete type 'void'
static_assert(sizeof(_Tp) > 0, "Type must be complete.");
^~~~~~~~~~~
/usr/bin/../include/c++/v1/type_traits:2778:15: note: in instantiation of template class
'std::__1::__check_complete<void>' requested here
: private __check_complete<_Rp>
^
/usr/bin/../include/c++/v1/type_traits:2947:15: note: in instantiation of template class
'std::__1::__check_complete<void (*)(std::__1::atomic<unsigned int> &)>' requested here
: private __check_complete<_Fp>
^
/usr/bin/../include/c++/v1/type_traits:2958:11: note: in instantiation of template class
'std::__1::__invokable_imp<void (*)(std::__1::atomic<unsigned int> &),
std::__1::reference_wrapper<std::__1::atomic<unsigned int> > >' requested here
__invokable_imp<_Fp, _Args...>::value>
^
/usr/bin/../include/c++/v1/type_traits:2977:30: note: in instantiation of template class 'std::__1::__invokable<void
(*)(std::__1::atomic<unsigned int> &), std::__1::reference_wrapper<std::__1::atomic<unsigned int> > >' requested
here
: public __invoke_of_imp<__invokable<_Fp, _Args...>::value, _Fp, _Args...>
^
/usr/bin/../include/c++/v1/future:2237:17: note: in instantiation of template class 'std::__1::__invoke_of<void
(*)(std::__1::atomic<unsigned int> &), std::__1::reference_wrapper<std::__1::atomic<unsigned int> > >' requested
here
future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
^
future_1.cpp:19:17: note: while substituting deduced template arguments into function template 'async' [with _Fp = void
(*)(std::__1::atomic<unsigned int> &), _Args = <std::__1::reference_wrapper<std::__1::atomic<unsigned int> >>]
consumeFuture(std::async(std::launch::async, &actOnT<uint32_t>, std::ref(a)));
^
1 error generated.
libc++ 的这个修订版修复了这个问题: http://llvm.org/viewvc/llvm-project?view=revision&revision=188413
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- 在Linux中哪里可以找到互斥、未来等的源代码
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- C++发布版本中的未来错误值
- 从标准::未来<void>到非标量标准::未来<bool>引发的错误转换
- 使用C++未来值作为函数堆栈中的中间值会导致段错误
- libc++的一个错误?未来和C++11
- STD未来异常-已检索,STD错误
- 在运行时使用未来的c++分割错误