1 // Copyright (C) 2015-2022 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++11 } }
19 // COW strings don't support C++11 allocator propagation:
20 // { dg-require-effective-target cxx11_abi }
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
28 using traits
= std::char_traits
<C
>;
30 using __gnu_test::propagating_allocator
;
34 typedef propagating_allocator
<C
, false> alloc_type
;
35 typedef std::basic_string
<C
, traits
, alloc_type
> test_type
;
37 static_assert(std::is_move_assignable
<test_type
>::value
, "");
38 static_assert(!std::is_nothrow_move_assignable
<test_type
>::value
, "");
40 test_type
v1(alloc_type(1));
42 test_type
v2(alloc_type(2));
45 VERIFY(1 == v1
.get_allocator().get_personality());
46 VERIFY(2 == v2
.get_allocator().get_personality());
48 test_type
v3(alloc_type(3));
50 test_type
v4(alloc_type(4));
53 VERIFY(3 == v3
.get_allocator().get_personality());
54 VERIFY(4 == v4
.get_allocator().get_personality());
56 test_type
v5(alloc_type(5));
58 test_type
v6(alloc_type(6));
61 VERIFY(5 == v5
.get_allocator().get_personality());
62 VERIFY(6 == v6
.get_allocator().get_personality());
64 test_type
v7(alloc_type(7));
66 test_type
v8(alloc_type(8));
69 VERIFY(7 == v7
.get_allocator().get_personality());
70 VERIFY(8 == v8
.get_allocator().get_personality());
75 typedef propagating_allocator
<C
, true> alloc_type
;
76 typedef std::basic_string
<C
, traits
, alloc_type
> test_type
;
78 test_type
v1(alloc_type(1));
80 test_type
v2(alloc_type(2));
83 VERIFY(1 == v1
.get_allocator().get_personality());
84 VERIFY(1 == v2
.get_allocator().get_personality());
86 test_type
v3(alloc_type(3));
88 test_type
v4(alloc_type(4));
91 VERIFY(3 == v3
.get_allocator().get_personality());
92 VERIFY(3 == v4
.get_allocator().get_personality());
94 test_type
v5(alloc_type(5));
96 test_type
v6(alloc_type(6));
99 VERIFY(5 == v5
.get_allocator().get_personality());
100 VERIFY(5 == v6
.get_allocator().get_personality());
102 test_type
v7(alloc_type(7));
104 test_type
v8(alloc_type(8));
107 VERIFY(7 == v7
.get_allocator().get_personality());
108 VERIFY(7 == v8
.get_allocator().get_personality());
113 typedef propagating_allocator
<C
, false> alloc_type
;
114 typedef std::basic_string
<C
, traits
, alloc_type
> test_type
;
116 test_type
v1(alloc_type(1));
118 test_type
v2(alloc_type(1));
121 VERIFY(1 == v1
.get_allocator().get_personality());
122 VERIFY(1 == v2
.get_allocator().get_personality());
124 test_type
v3(alloc_type(3));
126 test_type
v4(alloc_type(3));
129 VERIFY(3 == v3
.get_allocator().get_personality());
130 VERIFY(3 == v4
.get_allocator().get_personality());
132 test_type
v5(alloc_type(5));
134 test_type
v6(alloc_type(5));
137 VERIFY(5 == v5
.get_allocator().get_personality());
138 VERIFY(5 == v6
.get_allocator().get_personality());
140 test_type
v7(alloc_type(7));
142 test_type
v8(alloc_type(7));
145 VERIFY(7 == v7
.get_allocator().get_personality());
146 VERIFY(7 == v8
.get_allocator().get_personality());