Ticket #4980: bug.cc

File bug.cc, 965 bytes (added by michal.pecio@…, 12 years ago)

bug demonstration

Line 
1#include <exception>
2#include <iostream>
3#include <boost/intrusive/set.hpp>
4using namespace std;
5using namespace boost::intrusive;
6
7class ex : public std::exception {
8public:
9 virtual const char * what() const throw() {
10 return "diediedie";
11 }
12};
13
14struct evil {
15 set_member_hook<> hook;
16
17 bool operator< (const evil& b) const {
18 cout << __func__ << endl;
19 throw ex();
20 }
21 bool operator> (const evil& b) const {
22 cout << __func__ << endl;
23 throw ex();
24 }
25};
26
27typedef multiset<evil, member_hook<evil, set_member_hook<>, &evil::hook> > mus;
28
29int main () {
30 evil x, y;
31 mus set;
32 cout << set.size() << endl;
33 set.insert(x);
34 cout << set.size() << endl;
35 try {
36 set.insert(y);
37 } catch(exception &e) {
38 cout << e.what() << endl;
39 }
40 cout << set.size() << endl;
41 for (mus::iterator i = set.begin(); i != set.end(); ++i)
42 cout << '.';
43 cout << endl;
44}
45/*** OUTPUT: ***
460
471
48operator<
49diediedie
502
51.
52*** EXPECTED OUTPUT:
530
541
55operator<
56diediedie
571
58.
59***************/