1 | // unordered_bug.cxx
|
---|
2 | // Crash with unordered_multimap::erase(iterator, iterator)
|
---|
3 |
|
---|
4 | // g++ -m64 unordered_bug.cxx -O3 -o unordered_bug -I/wrk/hdstaff/stevenl/p4/work_tmp/HEAD/src/ext/Boost/boost_1_51_0
|
---|
5 |
|
---|
6 |
|
---|
7 | #include <iostream>
|
---|
8 | #include "boost/unordered_map.hpp"
|
---|
9 |
|
---|
10 | double
|
---|
11 | msec(clock_t start, clock_t end)
|
---|
12 | {
|
---|
13 | return ((end - start) * 1000/CLOCKS_PER_SEC);
|
---|
14 | }
|
---|
15 |
|
---|
16 | void
|
---|
17 | fill_unordered(int items)
|
---|
18 | {
|
---|
19 | boost::unordered_multimap<int, int> hashmap;
|
---|
20 |
|
---|
21 | for (int i=0,j=items-1; i<j; ++i,--j)
|
---|
22 | {
|
---|
23 | hashmap.insert(boost::unordered_multimap<int, int>::value_type(i, i));
|
---|
24 | hashmap.insert(boost::unordered_multimap<int, int>::value_type(i, i+1));
|
---|
25 |
|
---|
26 | if (i > 2) {
|
---|
27 | #if 1
|
---|
28 | // crash
|
---|
29 | std::pair<boost::unordered_multimap<int, int>::iterator, boost::unordered_multimap<int, int>::iterator> p = hashmap.equal_range(i - 2);
|
---|
30 |
|
---|
31 | hashmap.erase(p.first, p.second);
|
---|
32 | #else
|
---|
33 | // fine
|
---|
34 | hashmap.erase(i-2);
|
---|
35 | #endif
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | void
|
---|
42 | fill (int items)
|
---|
43 | {
|
---|
44 | {
|
---|
45 | std::cout << "filling unordered\n";
|
---|
46 | clock_t start = clock();
|
---|
47 |
|
---|
48 | fill_unordered(items);
|
---|
49 |
|
---|
50 | clock_t end = clock();
|
---|
51 | std::cout << "elapsed time: " << msec(start,end) << "ms\n";
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | int main(int argc, char* argv[])
|
---|
56 | {
|
---|
57 | if (argc < 2) {
|
---|
58 | std::cout << "usage: fill <int>\n";
|
---|
59 | return 1;
|
---|
60 | }
|
---|
61 |
|
---|
62 | int items = std::atoi(argv[1]);
|
---|
63 | std::cout << "items: " << items << "\n";
|
---|
64 | fill(items);
|
---|
65 | return 0;
|
---|
66 | }
|
---|