c++: Fix ICE with #embed/RAW_DATA_CST after list conversion [PR118671]
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / priority_queue / 118088.cc
blobb59175d8786a60fb344701c978b72eb5c34f41c5
1 // { dg-do run { target c++11 } }
3 #include <queue>
4 #include <vector>
5 #include <testsuite_hooks.h>
7 template<typename T, typename Seq>
8 bool
9 check(std::priority_queue<T, Seq>& p)
11 if (!p.empty())
13 T prev = p.top();
14 p.pop();
15 while (!p.empty())
17 if ( prev < p.top() )
18 return false;
19 prev = p.top();
20 p.pop();
23 return true;
26 // A vector-like type that has a non-empty moved-from state.
27 struct Vector : std::vector<int>
29 using Base = std::vector<int>;
31 using Base::Base;
33 Vector(const Vector&) = default;
34 Vector& operator=(const Vector&) = default;
36 Vector(Vector&& v) : Base(static_cast<const Base&>(v))
38 invalidate_heap(v);
41 Vector(Vector&& v, const std::allocator<int>&)
42 : Base(static_cast<const Base&>(v))
44 invalidate_heap(v);
47 Vector&
48 operator=(Vector&& v)
50 static_cast<Base&>(*this) = static_cast<const Base&>(v);
51 invalidate_heap(v);
52 return *this;
55 void invalidate_heap(Base& v) { v = {1,2,3}; }
58 void
59 test_moves()
61 std::priority_queue<int, Vector> p;
62 p.push(1);
63 p.push(3);
64 p.push(5);
65 p.push(2);
66 p.push(2);
67 p.push(2);
68 p.push(2);
69 std::priority_queue<int, Vector> p2 = std::move(p);
70 VERIFY( check(p) );
72 // Allocator-extended move constructor:
73 std::priority_queue<int, Vector> p3(std::move(p2), std::allocator<int>());
74 VERIFY( check(p2) );
76 p2 = std::move(p3);
77 VERIFY( check(p3) );
80 int main()
82 test_moves();