Debian Codegraph @

libstdc++-v3/testsuite/21_strings/basic_string/allocator/116641.cc

raw
1 // { dg-do run { target c++11 } }
2 // { dg-require-effective-target cxx11_abi }
3
4 // Bug 116641 - std::string move assignment incorrectly depends on POCCA
5
6 #include <string>
7 #include <testsuite_hooks.h>
8
9 template<typename T>
10 struct Alloc
11 {
12 using value_type = T;
13 using propagate_on_container_swap = std::false_type;
14 using propagate_on_container_copy_assignment = std::true_type;
15 using propagate_on_container_move_assignment = std::false_type;
16
17 Alloc(int id) : id(id) { }
18
19 template<typename U>
20 Alloc(const Alloc<U>& a) : id(a.id) { }
21
22 T* allocate(unsigned long n)
23 { return std::allocator<T>().allocate(n); }
24
25 void deallocate(T* p, unsigned long n)
26 { std::allocator<T>().deallocate(p, n); }
27
28 Alloc& operator=(const Alloc&) { throw; }
29
30 bool operator==(const Alloc& a) const { return id == a.id; }
31 bool operator!=(const Alloc& a) const { return id != a.id; }
32
33 int id;
34 };
35
36 void
37 test_pr116641()
38 {
39 Alloc<char> a1(1), a2(2);
40 std::basic_string<char, std::char_traits<char>, Alloc<char>> s1(a1), s2(a2);
41
42 s1 = "allocator should not propagate on move assignment";
43 VERIFY( s1.get_allocator() == a1 );
44 VERIFY( s2.get_allocator() == a2 );
45 s2 = std::move(s1);
46 VERIFY( s1.get_allocator() == a1 );
47 VERIFY( s2.get_allocator() == a2 );
48 }
49
50 int main()
51 {
52 test_pr116641();
53 }