boost :: container :: flat_multimap在OSX/Appleclang上以发行模式崩溃
boost::container::flat_multimap crash on OSX/AppleClang in Release mode
我似乎在macOS/appleclang上的boost :: facteraper :: facter_multimap(boost 1.66.0(中有一个问题。我在Ubuntu 17.10/GCC7.2和Oracle Linux/GCC7.2.1中进行了测试,并且这些问题没有出现。
下面是一个最小可重复的示例。
代码:
#include <iostream>
#include <vector>
#include <boost/container/flat_map.hpp>
using multimap = boost::container::flat_multimap<int *, int>;
int main(int argc, char **argv)
{
multimap map;
std::vector<std::pair<int *, int>> key_value_pairs;
for (int k = 0; k < 2; k++) {
int * new_int = new int;
*new_int = k;
map.emplace(new_int, k);
key_value_pairs.emplace_back(new_int, k);
}
for (auto it = map.begin(); it != map.end();) {
if (it->first == key_value_pairs[0].first) {
it = map.erase(it);
} else {
++it;
}
}
// Should only be one map element left (key_value_pairs[1])
auto it = map.find(key_value_pairs[1].first);
if (it == map.end()) {
throw std::logic_error("Could not find key");
}
std::cout << "Success!" << std::endl;
return EXIT_SUCCESS;
}
clang版本
hoc$ clang --version
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
在此示例中,我们生成2个int指针,并将它们作为键插入boost :: container :: flat_multimap中。然后,我们通过识别钥匙来遍历地图并删除其中一个条目。随后,我们尝试通过键找到非捕获元素,但有时找不到它(有时会触发第31行的std :: logic_error(。
我的代码中有错误吗?或容器?
我实际上什么都没看见/错误/用代码。
有很多代码气味 - 这里的"等效"程序是否显示同样的问题?
活在coliru
#include <boost/container/flat_map.hpp>
#include <iostream>
#include <vector>
using multimap = boost::container::flat_multimap<int *, int>;
int main() {
int ks[] = { 0, 1 }; // allocation pool outlives map and key_value_pairs
multimap map;
for (int &k : ks)
map.emplace(&k, k);
std::vector<multimap::value_type> const key_value_pairs(map.begin(), map.end());
map.erase(key_value_pairs[0].first);
assert(map.size() == 1);
assert(map.begin()->first == key_value_pairs[1].first);
assert(map.count(&ks[0]) == 0);
assert(map.count(&ks[1]) == 1);
}
相关文章:
- LoadLibrary:在发布模式下崩溃
- 在发布模式下崩溃,但如果可调试为 true - 不是..什么是可能的问题
- boost :: container :: flat_multimap在OSX/Appleclang上以发行模式崩溃
- MSVC 编译器在调试模式下构建 Qt 5.10 时崩溃
- 一般来说,使用Qt Creator,是什么导致程序在调试模式下编译时正确运行,但在发布模式下崩溃
- 在发行模式下开放的软崩溃(调试工作正常)
- MFC 结束对话框崩溃时模式对话框没有焦点
- GCC 在调试模式下崩溃,在发布模式下运行良好
- 在发布模式下崩溃,在调试模式下遇到错误
- C++: __try..__除了;在发布模式下隐藏崩溃
- 通过在 C++ 中使用发布模式二进制文件获取崩溃原因
- cd库:在推送自定义类型的派生类型时(仅在发布模式下),michael_deque会导致崩溃
- wglCreateContextAttribsARB在x64平台下的调试模式下崩溃
- 当结构具有默认构造函数时,为什么我的C++程序在发布模式下崩溃
- boost::any_range<gsl::string_span<>> 在发布模式下崩溃
- 释放模式下的boost线程崩溃
- OCCI应用程序在Visual Studio 2005的调试模式下运行时会崩溃
- c++全系统崩溃,仅发布模式
- Directshow渲染过滤器只在发布模式下崩溃
- Visual Studio 2008-vftable指针不正确?调试模式崩溃,发布即可