]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/allocator/wchar_t/move_assign.cc
Implement N4258 noexcept for std::basic_string.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / allocator / wchar_t / move_assign.cc
CommitLineData
5caff414
JW
1// Copyright (C) 2015 Free Software Foundation, Inc.
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.
8
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.
13
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
18// { dg-options "-std=gnu++11" }
19
20#include <string>
21#include <testsuite_hooks.h>
22#include <testsuite_allocator.h>
23
24#if _GLIBCXX_USE_CXX11_ABI && defined(_GLIBCXX_USE_WCHAR_T)
25using C = char;
26const C c = 'a';
27using traits = std::char_traits<C>;
28
29using __gnu_test::propagating_allocator;
30
31void test01()
32{
33 bool test __attribute__((unused)) = true;
34 typedef propagating_allocator<C, false> alloc_type;
35 typedef std::basic_string<C, traits, alloc_type> test_type;
36
37 test_type v1(alloc_type(1));
38 v1.assign(1, c);
39 test_type v2(alloc_type(2));
40 v2.assign(1, c);
41 v2 = std::move(v1);
42 VERIFY(1 == v1.get_allocator().get_personality());
43 VERIFY(2 == v2.get_allocator().get_personality());
44
45 test_type v3(alloc_type(3));
46 v3.assign(1, c);
47 test_type v4(alloc_type(4));
48 v4.assign(100, c);
49 v4 = std::move(v3);
50 VERIFY(3 == v3.get_allocator().get_personality());
51 VERIFY(4 == v4.get_allocator().get_personality());
52
53 test_type v5(alloc_type(5));
54 v5.assign(100, c);
55 test_type v6(alloc_type(6));
56 v6.assign(1, c);
57 v6 = std::move(v5);
58 VERIFY(5 == v5.get_allocator().get_personality());
59 VERIFY(6 == v6.get_allocator().get_personality());
60
61 test_type v7(alloc_type(7));
62 v7.assign(100, c);
63 test_type v8(alloc_type(8));
64 v8.assign(100, c);
65 v8 = std::move(v7);
66 VERIFY(7 == v7.get_allocator().get_personality());
67 VERIFY(8 == v8.get_allocator().get_personality());
68}
69
70void test02()
71{
72 bool test __attribute__((unused)) = true;
73 typedef propagating_allocator<C, true> alloc_type;
74 typedef std::basic_string<C, traits, alloc_type> test_type;
75
76 test_type v1(alloc_type(1));
77 v1.assign(1, c);
78 test_type v2(alloc_type(2));
79 v2.assign(1, c);
80 v2 = std::move(v1);
81 VERIFY(0 == v1.get_allocator().get_personality());
82 VERIFY(1 == v2.get_allocator().get_personality());
83
84 test_type v3(alloc_type(3));
85 v3.assign(1, c);
86 test_type v4(alloc_type(4));
87 v4.assign(100, c);
88 v4 = std::move(v3);
89 VERIFY(0 == v3.get_allocator().get_personality());
90 VERIFY(3 == v4.get_allocator().get_personality());
91
92 test_type v5(alloc_type(5));
93 v5.assign(100, c);
94 test_type v6(alloc_type(6));
95 v6.assign(1, c);
96 v6 = std::move(v5);
97 VERIFY(0 == v5.get_allocator().get_personality());
98 VERIFY(5 == v6.get_allocator().get_personality());
99
100 test_type v7(alloc_type(7));
101 v7.assign(100, c);
102 test_type v8(alloc_type(8));
103 v8.assign(100, c);
104 v8 = std::move(v7);
105 VERIFY(0 == v7.get_allocator().get_personality());
106 VERIFY(7 == v8.get_allocator().get_personality());
107}
108
109void test03()
110{
111 bool test __attribute__((unused)) = true;
112 typedef propagating_allocator<C, false> alloc_type;
113 typedef std::basic_string<C, traits, alloc_type> test_type;
114
115 test_type v1(alloc_type(1));
116 v1.assign(1, c);
117 test_type v2(alloc_type(1));
118 v2.assign(1, c);
119 v2 = std::move(v1);
120 VERIFY(1 == v1.get_allocator().get_personality());
121 VERIFY(1 == v2.get_allocator().get_personality());
122
123 test_type v3(alloc_type(3));
124 v3.assign(1, c);
125 test_type v4(alloc_type(3));
126 v4.assign(100, c);
127 v4 = std::move(v3);
128 VERIFY(3 == v3.get_allocator().get_personality());
129 VERIFY(3 == v4.get_allocator().get_personality());
130
131 test_type v5(alloc_type(5));
132 v5.assign(100, c);
133 test_type v6(alloc_type(5));
134 v6.assign(1, c);
135 v6 = std::move(v5);
136 VERIFY(5 == v5.get_allocator().get_personality());
137 VERIFY(5 == v6.get_allocator().get_personality());
138
139 test_type v7(alloc_type(7));
140 v7.assign(100, c);
141 test_type v8(alloc_type(7));
142 v8.assign(100, c);
143 v8 = std::move(v7);
144 VERIFY(7 == v7.get_allocator().get_personality());
145 VERIFY(7 == v8.get_allocator().get_personality());
146}
147
148int main()
149{
150 test01();
151 test02();
152 test03();
153 return 0;
154}
155#else
156int main()
157{
158 // COW strings don't support C++11 allocators
159}
160#endif