]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | // Copyright (C) 2015-2021 Free Software Foundation, Inc. |
5caff414 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
5e961dba | 8 | |
5caff414 JW |
9 | // This library is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
5e961dba | 13 | |
5caff414 JW |
14 | // You should have received a copy of the GNU General Public License along |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
52066eae | 18 | // { dg-do run { target c++11 } } |
5e961dba | 19 | // COW strings don't support C++11 allocator propagation: |
90aa7330 | 20 | // { dg-require-effective-target cxx11-abi } |
5caff414 JW |
21 | |
22 | #include <string> | |
23 | #include <testsuite_hooks.h> | |
24 | #include <testsuite_allocator.h> | |
5e961dba | 25 | |
589a30d1 JW |
26 | using C = wchar_t; |
27 | const C c = L'a'; | |
5caff414 JW |
28 | using traits = std::char_traits<C>; |
29 | ||
30 | using __gnu_test::propagating_allocator; | |
31 | ||
32 | void test01() | |
33 | { | |
5caff414 JW |
34 | typedef propagating_allocator<C, false> alloc_type; |
35 | typedef std::basic_string<C, traits, alloc_type> test_type; | |
36 | ||
d8d9b83b JW |
37 | static_assert(std::is_move_assignable<test_type>::value, ""); |
38 | static_assert(!std::is_nothrow_move_assignable<test_type>::value, ""); | |
39 | ||
5caff414 JW |
40 | test_type v1(alloc_type(1)); |
41 | v1.assign(1, c); | |
42 | test_type v2(alloc_type(2)); | |
43 | v2.assign(1, c); | |
44 | v2 = std::move(v1); | |
45 | VERIFY(1 == v1.get_allocator().get_personality()); | |
46 | VERIFY(2 == v2.get_allocator().get_personality()); | |
47 | ||
48 | test_type v3(alloc_type(3)); | |
49 | v3.assign(1, c); | |
50 | test_type v4(alloc_type(4)); | |
51 | v4.assign(100, c); | |
52 | v4 = std::move(v3); | |
53 | VERIFY(3 == v3.get_allocator().get_personality()); | |
54 | VERIFY(4 == v4.get_allocator().get_personality()); | |
55 | ||
56 | test_type v5(alloc_type(5)); | |
57 | v5.assign(100, c); | |
58 | test_type v6(alloc_type(6)); | |
59 | v6.assign(1, c); | |
60 | v6 = std::move(v5); | |
61 | VERIFY(5 == v5.get_allocator().get_personality()); | |
62 | VERIFY(6 == v6.get_allocator().get_personality()); | |
63 | ||
64 | test_type v7(alloc_type(7)); | |
65 | v7.assign(100, c); | |
66 | test_type v8(alloc_type(8)); | |
67 | v8.assign(100, c); | |
68 | v8 = std::move(v7); | |
69 | VERIFY(7 == v7.get_allocator().get_personality()); | |
70 | VERIFY(8 == v8.get_allocator().get_personality()); | |
71 | } | |
72 | ||
73 | void test02() | |
74 | { | |
5caff414 JW |
75 | typedef propagating_allocator<C, true> alloc_type; |
76 | typedef std::basic_string<C, traits, alloc_type> test_type; | |
77 | ||
78 | test_type v1(alloc_type(1)); | |
79 | v1.assign(1, c); | |
80 | test_type v2(alloc_type(2)); | |
81 | v2.assign(1, c); | |
82 | v2 = std::move(v1); | |
935469da | 83 | VERIFY(1 == v1.get_allocator().get_personality()); |
5caff414 JW |
84 | VERIFY(1 == v2.get_allocator().get_personality()); |
85 | ||
86 | test_type v3(alloc_type(3)); | |
87 | v3.assign(1, c); | |
88 | test_type v4(alloc_type(4)); | |
89 | v4.assign(100, c); | |
90 | v4 = std::move(v3); | |
935469da | 91 | VERIFY(3 == v3.get_allocator().get_personality()); |
5caff414 JW |
92 | VERIFY(3 == v4.get_allocator().get_personality()); |
93 | ||
94 | test_type v5(alloc_type(5)); | |
95 | v5.assign(100, c); | |
96 | test_type v6(alloc_type(6)); | |
97 | v6.assign(1, c); | |
98 | v6 = std::move(v5); | |
935469da | 99 | VERIFY(5 == v5.get_allocator().get_personality()); |
5caff414 JW |
100 | VERIFY(5 == v6.get_allocator().get_personality()); |
101 | ||
102 | test_type v7(alloc_type(7)); | |
103 | v7.assign(100, c); | |
104 | test_type v8(alloc_type(8)); | |
105 | v8.assign(100, c); | |
106 | v8 = std::move(v7); | |
935469da | 107 | VERIFY(7 == v7.get_allocator().get_personality()); |
5caff414 JW |
108 | VERIFY(7 == v8.get_allocator().get_personality()); |
109 | } | |
110 | ||
111 | void test03() | |
112 | { | |
5caff414 JW |
113 | typedef propagating_allocator<C, false> alloc_type; |
114 | typedef std::basic_string<C, traits, alloc_type> test_type; | |
115 | ||
116 | test_type v1(alloc_type(1)); | |
117 | v1.assign(1, c); | |
118 | test_type v2(alloc_type(1)); | |
119 | v2.assign(1, c); | |
120 | v2 = std::move(v1); | |
121 | VERIFY(1 == v1.get_allocator().get_personality()); | |
122 | VERIFY(1 == v2.get_allocator().get_personality()); | |
123 | ||
124 | test_type v3(alloc_type(3)); | |
125 | v3.assign(1, c); | |
126 | test_type v4(alloc_type(3)); | |
127 | v4.assign(100, c); | |
128 | v4 = std::move(v3); | |
129 | VERIFY(3 == v3.get_allocator().get_personality()); | |
130 | VERIFY(3 == v4.get_allocator().get_personality()); | |
131 | ||
132 | test_type v5(alloc_type(5)); | |
133 | v5.assign(100, c); | |
134 | test_type v6(alloc_type(5)); | |
135 | v6.assign(1, c); | |
136 | v6 = std::move(v5); | |
137 | VERIFY(5 == v5.get_allocator().get_personality()); | |
138 | VERIFY(5 == v6.get_allocator().get_personality()); | |
139 | ||
140 | test_type v7(alloc_type(7)); | |
141 | v7.assign(100, c); | |
142 | test_type v8(alloc_type(7)); | |
143 | v8.assign(100, c); | |
144 | v8 = std::move(v7); | |
145 | VERIFY(7 == v7.get_allocator().get_personality()); | |
146 | VERIFY(7 == v8.get_allocator().get_personality()); | |
147 | } | |
148 | ||
149 | int main() | |
150 | { | |
151 | test01(); | |
152 | test02(); | |
153 | test03(); | |
154 | return 0; | |
155 | } |