1dd3ba794SEric Fiselier //===----------------------------------------------------------------------===//
2dd3ba794SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6dd3ba794SEric Fiselier //
7dd3ba794SEric Fiselier //===----------------------------------------------------------------------===//
8dd3ba794SEric Fiselier 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10dd3ba794SEric Fiselier 
11dd3ba794SEric Fiselier // <string>
12dd3ba794SEric Fiselier 
13dd3ba794SEric Fiselier // Test that the constructors offered by std::basic_string are formulated
14dd3ba794SEric Fiselier // so they're compatible with implicit deduction guides.
15dd3ba794SEric Fiselier 
16dd3ba794SEric Fiselier #include <string>
17dd3ba794SEric Fiselier #include <string_view>
18dd3ba794SEric Fiselier #include <cassert>
19dd3ba794SEric Fiselier 
20dd3ba794SEric Fiselier #include "test_macros.h"
21dd3ba794SEric Fiselier #include "test_allocator.h"
22dd3ba794SEric Fiselier #include "test_iterators.h"
23cc89063bSNico Weber #include "constexpr_char_traits.h"
24dd3ba794SEric Fiselier 
25dd3ba794SEric Fiselier template <class T, class Alloc = std::allocator<T>>
26dd3ba794SEric Fiselier using BStr = std::basic_string<T, std::char_traits<T>, Alloc>;
27dd3ba794SEric Fiselier 
28dd3ba794SEric Fiselier // Overloads
29dd3ba794SEric Fiselier //  using A = Allocator;
30dd3ba794SEric Fiselier //  using BS = basic_string
31dd3ba794SEric Fiselier //  using BSV = basic_string_view
32dd3ba794SEric Fiselier // ---------------
33dd3ba794SEric Fiselier // (1)  basic_string() - NOT TESTED
34dd3ba794SEric Fiselier // (2)  basic_string(A const&) - BROKEN
35dd3ba794SEric Fiselier // (3)  basic_string(size_type, CharT, const A& = A())
36dd3ba794SEric Fiselier // (4)  basic_string(BS const&, size_type, A const& = A())
3776b26852SMarshall Clow // (5)  basic_string(BS const&, size_type, size_type, A const& = A())
38dd3ba794SEric Fiselier // (6)  basic_string(const CharT*, size_type, A const& = A())
39dd3ba794SEric Fiselier // (7)  basic_string(const CharT*, A const& = A())
40dd3ba794SEric Fiselier // (8)  basic_string(InputIt, InputIt, A const& = A()) - BROKEN
41dd3ba794SEric Fiselier // (9)  basic_string(BS const&)
42dd3ba794SEric Fiselier // (10) basic_string(BS const&, A const&)
43dd3ba794SEric Fiselier // (11) basic_string(BS&&)
44dd3ba794SEric Fiselier // (12) basic_string(BS&&, A const&)
45dd3ba794SEric Fiselier // (13) basic_string(initializer_list<CharT>, A const& = A())
46dd3ba794SEric Fiselier // (14) basic_string(BSV, A const& = A())
4776b26852SMarshall Clow // (15) basic_string(const T&, size_type, size_type, A const& = A())
test()48*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 bool test() {
49e85018b7SNikolas Klauser 
50dd3ba794SEric Fiselier   using TestSizeT = test_allocator<char>::size_type;
51dd3ba794SEric Fiselier   { // Testing (1)
529ff51bf9SLouis Dionne     // Nothing to do. Cannot deduce without any arguments.
53dd3ba794SEric Fiselier   }
54dd3ba794SEric Fiselier   { // Testing (2)
55dd3ba794SEric Fiselier     // This overload isn't compatible with implicit deduction guides as
56dd3ba794SEric Fiselier     // specified in the standard.
57dd3ba794SEric Fiselier     // const test_allocator<char> alloc{};
58dd3ba794SEric Fiselier     // std::basic_string s(alloc);
59dd3ba794SEric Fiselier   }
60dd3ba794SEric Fiselier   { // Testing (3) w/o allocator
61dd3ba794SEric Fiselier     std::basic_string s(6ull, 'a');
62dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
63dd3ba794SEric Fiselier     assert(s == "aaaaaa");
64dd3ba794SEric Fiselier 
65f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
66dd3ba794SEric Fiselier     std::basic_string w(2ull, L'b');
67dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), std::wstring);
68dd3ba794SEric Fiselier     assert(w == L"bb");
69f4c1258dSLouis Dionne #endif
70dd3ba794SEric Fiselier   }
71dd3ba794SEric Fiselier   { // Testing (3) w/ allocator
72dd3ba794SEric Fiselier     std::basic_string s(6ull, 'a', test_allocator<char>{});
73dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), BStr<char,test_allocator<char>>);
74dd3ba794SEric Fiselier     assert(s == "aaaaaa");
75dd3ba794SEric Fiselier 
76f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
77dd3ba794SEric Fiselier     std::basic_string w(2ull, L'b', test_allocator<wchar_t>{});
78dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), BStr<wchar_t, test_allocator<wchar_t>>);
79dd3ba794SEric Fiselier     assert(w == L"bb");
80f4c1258dSLouis Dionne #endif
81dd3ba794SEric Fiselier   }
82dd3ba794SEric Fiselier   { // Testing (4) w/o allocator
83dd3ba794SEric Fiselier     const std::string sin("abc");
84dd3ba794SEric Fiselier     std::basic_string s(sin, (size_t)1);
85dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
86dd3ba794SEric Fiselier     assert(s == "bc");
87dd3ba794SEric Fiselier 
88f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
89dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
90dd3ba794SEric Fiselier                                   constexpr_char_traits<wchar_t>,
91dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
92dd3ba794SEric Fiselier     const WStr win(L"abcdef");
93dd3ba794SEric Fiselier     std::basic_string w(win, (TestSizeT)3);
94dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
95dd3ba794SEric Fiselier     assert(w == L"def");
96f4c1258dSLouis Dionne #endif
97dd3ba794SEric Fiselier   }
98dd3ba794SEric Fiselier   { // Testing (4) w/ allocator
99dd3ba794SEric Fiselier     const std::string sin("abc");
100dd3ba794SEric Fiselier     std::basic_string s(sin, (size_t)1, std::allocator<char>{});
101dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
102dd3ba794SEric Fiselier     assert(s == "bc");
103dd3ba794SEric Fiselier 
104f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
105dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
106dd3ba794SEric Fiselier                                   constexpr_char_traits<wchar_t>,
107dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
108dd3ba794SEric Fiselier     const WStr win(L"abcdef");
109dd3ba794SEric Fiselier     std::basic_string w(win, (TestSizeT)3, test_allocator<wchar_t>{});
110dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
111dd3ba794SEric Fiselier     assert(w == L"def");
112f4c1258dSLouis Dionne #endif
113dd3ba794SEric Fiselier   }
114dd3ba794SEric Fiselier   { // Testing (5) w/o allocator
115dd3ba794SEric Fiselier     const std::string sin("abc");
116dd3ba794SEric Fiselier     std::basic_string s(sin, (size_t)1, (size_t)3);
117dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
118dd3ba794SEric Fiselier     assert(s == "bc");
119dd3ba794SEric Fiselier 
120f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
121dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
122dd3ba794SEric Fiselier                                   constexpr_char_traits<wchar_t>,
123dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
124dd3ba794SEric Fiselier     const WStr win(L"abcdef");
125dd3ba794SEric Fiselier     std::basic_string w(win, (TestSizeT)2, (TestSizeT)3);
126dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
127dd3ba794SEric Fiselier     assert(w == L"cde");
128f4c1258dSLouis Dionne #endif
129dd3ba794SEric Fiselier   }
130dd3ba794SEric Fiselier   { // Testing (5) w/ allocator
131dd3ba794SEric Fiselier     const std::string sin("abc");
132dd3ba794SEric Fiselier     std::basic_string s(sin, (size_t)1, (size_t)3, std::allocator<char>{});
133dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
134dd3ba794SEric Fiselier     assert(s == "bc");
135dd3ba794SEric Fiselier 
136f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
137dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
138dd3ba794SEric Fiselier                                   constexpr_char_traits<wchar_t>,
139dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
140dd3ba794SEric Fiselier     const WStr win(L"abcdef");
141dd3ba794SEric Fiselier     std::basic_string w(win, (TestSizeT)2, (TestSizeT)3, test_allocator<wchar_t>{});
142dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
143dd3ba794SEric Fiselier     assert(w == L"cde");
144f4c1258dSLouis Dionne #endif
145dd3ba794SEric Fiselier   }
146dd3ba794SEric Fiselier   { // Testing (6) w/o allocator
147dd3ba794SEric Fiselier     std::basic_string s("abc", (size_t)2);
148dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
149dd3ba794SEric Fiselier     assert(s == "ab");
150dd3ba794SEric Fiselier 
151f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
152dd3ba794SEric Fiselier     std::basic_string w(L"abcdef", (size_t)3);
153dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), std::wstring);
154dd3ba794SEric Fiselier     assert(w == L"abc");
155f4c1258dSLouis Dionne #endif
156dd3ba794SEric Fiselier   }
157dd3ba794SEric Fiselier   { // Testing (6) w/ allocator
158dd3ba794SEric Fiselier     std::basic_string s("abc", (size_t)2, std::allocator<char>{});
159dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
160dd3ba794SEric Fiselier     assert(s == "ab");
161dd3ba794SEric Fiselier 
162f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
163dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
164dd3ba794SEric Fiselier                                   std::char_traits<wchar_t>,
165dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
166dd3ba794SEric Fiselier     std::basic_string w(L"abcdef", (TestSizeT)3, test_allocator<wchar_t>{});
167dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
168dd3ba794SEric Fiselier     assert(w == L"abc");
169f4c1258dSLouis Dionne #endif
170dd3ba794SEric Fiselier   }
171dd3ba794SEric Fiselier   { // Testing (7) w/o allocator
172dd3ba794SEric Fiselier     std::basic_string s("abc");
173dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
174dd3ba794SEric Fiselier     assert(s == "abc");
175dd3ba794SEric Fiselier 
176f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
177dd3ba794SEric Fiselier     std::basic_string w(L"abcdef");
178dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), std::wstring);
179dd3ba794SEric Fiselier     assert(w == L"abcdef");
180f4c1258dSLouis Dionne #endif
181dd3ba794SEric Fiselier   }
182dd3ba794SEric Fiselier   { // Testing (7) w/ allocator
183dd3ba794SEric Fiselier     std::basic_string s("abc", std::allocator<char>{});
184dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
185dd3ba794SEric Fiselier     assert(s == "abc");
186dd3ba794SEric Fiselier 
187f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
188dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
189dd3ba794SEric Fiselier                                   std::char_traits<wchar_t>,
190dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
191dd3ba794SEric Fiselier     std::basic_string w(L"abcdef", test_allocator<wchar_t>{});
192dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
193dd3ba794SEric Fiselier     assert(w == L"abcdef");
194f4c1258dSLouis Dionne #endif
195dd3ba794SEric Fiselier   }
196dd3ba794SEric Fiselier   { // (8) w/o allocator
197773ae441SChristopher Di Bella     using It = cpp17_input_iterator<const char*>;
198dd3ba794SEric Fiselier     const char* input = "abcdef";
199dd3ba794SEric Fiselier     std::basic_string s(It(input), It(input + 3), std::allocator<char>{});
200dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
20176b26852SMarshall Clow     assert(s == "abc");
20276b26852SMarshall Clow   }
20376b26852SMarshall Clow   { // (8) w/ allocator
204f4c1258dSLouis Dionne     {
205f4c1258dSLouis Dionne       using Expect = std::basic_string<char, std::char_traits<char>, test_allocator<char>>;
206f4c1258dSLouis Dionne       using It = cpp17_input_iterator<const char*>;
207f4c1258dSLouis Dionne       const char* input = "abcdef";
208f4c1258dSLouis Dionne       std::basic_string s(It(input), It(input + 3), test_allocator<char>{});
209f4c1258dSLouis Dionne       ASSERT_SAME_TYPE(decltype(s), Expect);
210f4c1258dSLouis Dionne       assert(s == "abc");
211f4c1258dSLouis Dionne     }
212f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
213f4c1258dSLouis Dionne     {
21476b26852SMarshall Clow       using ExpectW = std::basic_string<wchar_t, std::char_traits<wchar_t>, test_allocator<wchar_t>>;
215773ae441SChristopher Di Bella       using It = cpp17_input_iterator<const wchar_t*>;
21676b26852SMarshall Clow       const wchar_t* input = L"abcdef";
21776b26852SMarshall Clow       std::basic_string s(It(input), It(input + 3), test_allocator<wchar_t>{});
21876b26852SMarshall Clow       ASSERT_SAME_TYPE(decltype(s), ExpectW);
21976b26852SMarshall Clow       assert(s == L"abc");
220dd3ba794SEric Fiselier     }
221f4c1258dSLouis Dionne #endif
222f4c1258dSLouis Dionne   }
223dd3ba794SEric Fiselier   { // Testing (9)
224dd3ba794SEric Fiselier     const std::string sin("abc");
225dd3ba794SEric Fiselier     std::basic_string s(sin);
226dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
227dd3ba794SEric Fiselier     assert(s == "abc");
228dd3ba794SEric Fiselier 
229f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
230dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
231dd3ba794SEric Fiselier                                   constexpr_char_traits<wchar_t>,
232dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
233dd3ba794SEric Fiselier     const WStr win(L"abcdef");
234dd3ba794SEric Fiselier     std::basic_string w(win);
235dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
236dd3ba794SEric Fiselier     assert(w == L"abcdef");
237f4c1258dSLouis Dionne #endif
238dd3ba794SEric Fiselier   }
239dd3ba794SEric Fiselier   { // Testing (10)
240dd3ba794SEric Fiselier     const std::string sin("abc");
241dd3ba794SEric Fiselier     std::basic_string s(sin, std::allocator<char>{});
242dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
243dd3ba794SEric Fiselier     assert(s == "abc");
244dd3ba794SEric Fiselier 
245f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
246dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
247dd3ba794SEric Fiselier                                   constexpr_char_traits<wchar_t>,
248dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
249dd3ba794SEric Fiselier     const WStr win(L"abcdef");
250dd3ba794SEric Fiselier     std::basic_string w(win, test_allocator<wchar_t>{});
251dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
252dd3ba794SEric Fiselier     assert(w == L"abcdef");
253f4c1258dSLouis Dionne #endif
254dd3ba794SEric Fiselier   }
255dd3ba794SEric Fiselier   { // Testing (11)
256dd3ba794SEric Fiselier     std::string sin("abc");
257dd3ba794SEric Fiselier     std::basic_string s(std::move(sin));
258dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
259dd3ba794SEric Fiselier     assert(s == "abc");
260dd3ba794SEric Fiselier 
261f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
262dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
263dd3ba794SEric Fiselier                                   constexpr_char_traits<wchar_t>,
264dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
265dd3ba794SEric Fiselier     WStr win(L"abcdef");
266dd3ba794SEric Fiselier     std::basic_string w(std::move(win));
267dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
268dd3ba794SEric Fiselier     assert(w == L"abcdef");
269f4c1258dSLouis Dionne #endif
270dd3ba794SEric Fiselier   }
271dd3ba794SEric Fiselier   { // Testing (12)
272dd3ba794SEric Fiselier     std::string sin("abc");
273dd3ba794SEric Fiselier     std::basic_string s(std::move(sin), std::allocator<char>{});
274dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
275dd3ba794SEric Fiselier     assert(s == "abc");
276dd3ba794SEric Fiselier 
277f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
278dd3ba794SEric Fiselier     using WStr = std::basic_string<wchar_t,
279dd3ba794SEric Fiselier                                   constexpr_char_traits<wchar_t>,
280dd3ba794SEric Fiselier                                   test_allocator<wchar_t>>;
281dd3ba794SEric Fiselier     WStr win(L"abcdef");
282dd3ba794SEric Fiselier     std::basic_string w(std::move(win), test_allocator<wchar_t>{});
283dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), WStr);
284dd3ba794SEric Fiselier     assert(w == L"abcdef");
285f4c1258dSLouis Dionne #endif
286dd3ba794SEric Fiselier   }
287dd3ba794SEric Fiselier   { // Testing (13) w/o allocator
288dd3ba794SEric Fiselier     std::basic_string s({'a', 'b', 'c'});
289dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
290dd3ba794SEric Fiselier     assert(s == "abc");
291dd3ba794SEric Fiselier 
292f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
293dd3ba794SEric Fiselier     std::basic_string w({L'a', L'b', L'c'});
294dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), std::wstring);
295dd3ba794SEric Fiselier     assert(w == L"abc");
296f4c1258dSLouis Dionne #endif
297dd3ba794SEric Fiselier   }
298dd3ba794SEric Fiselier   { // Testing (13) w/ allocator
299dd3ba794SEric Fiselier     std::basic_string s({'a', 'b', 'c'}, test_allocator<char>{});
300dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), BStr<char, test_allocator<char>>);
301dd3ba794SEric Fiselier     assert(s == "abc");
302dd3ba794SEric Fiselier 
303f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
304dd3ba794SEric Fiselier     std::basic_string w({L'a', L'b', L'c'}, test_allocator<wchar_t>{});
305dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), BStr<wchar_t, test_allocator<wchar_t>>);
306dd3ba794SEric Fiselier     assert(w == L"abc");
307f4c1258dSLouis Dionne #endif
308dd3ba794SEric Fiselier   }
309dd3ba794SEric Fiselier   { // Testing (14) w/o allocator
310dd3ba794SEric Fiselier     std::string_view sv("abc");
311dd3ba794SEric Fiselier     std::basic_string s(sv);
312dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), std::string);
313dd3ba794SEric Fiselier     assert(s == "abc");
314dd3ba794SEric Fiselier 
315f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
316dd3ba794SEric Fiselier     using Expect = std::basic_string<wchar_t, constexpr_char_traits<wchar_t>>;
317dd3ba794SEric Fiselier     std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>> BSV(L"abcdef");
318dd3ba794SEric Fiselier     std::basic_string w(BSV);
319dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), Expect);
320dd3ba794SEric Fiselier     assert(w == L"abcdef");
321f4c1258dSLouis Dionne #endif
322dd3ba794SEric Fiselier   }
323dd3ba794SEric Fiselier   { // Testing (14) w/ allocator
324dd3ba794SEric Fiselier     using ExpectS = std::basic_string<char, std::char_traits<char>, test_allocator<char>>;
325dd3ba794SEric Fiselier     std::string_view sv("abc");
326dd3ba794SEric Fiselier     std::basic_string s(sv, test_allocator<char>{});
327dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(s), ExpectS);
328dd3ba794SEric Fiselier     assert(s == "abc");
329dd3ba794SEric Fiselier 
330f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
331dd3ba794SEric Fiselier     using ExpectW = std::basic_string<wchar_t, constexpr_char_traits<wchar_t>,
332dd3ba794SEric Fiselier                                       test_allocator<wchar_t>>;
333dd3ba794SEric Fiselier     std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>> BSV(L"abcdef");
334dd3ba794SEric Fiselier     std::basic_string w(BSV, test_allocator<wchar_t>{});
335dd3ba794SEric Fiselier     ASSERT_SAME_TYPE(decltype(w), ExpectW);
336dd3ba794SEric Fiselier     assert(w == L"abcdef");
337f4c1258dSLouis Dionne #endif
338dd3ba794SEric Fiselier   }
33976b26852SMarshall Clow   { // Testing (15) w/o allocator
34076b26852SMarshall Clow     std::string s0("abc");
34176b26852SMarshall Clow     std::basic_string s(s0, 1, 1);
34276b26852SMarshall Clow     ASSERT_SAME_TYPE(decltype(s), std::string);
34376b26852SMarshall Clow     assert(s == "b");
34476b26852SMarshall Clow 
345f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
34676b26852SMarshall Clow     std::wstring w0(L"abcdef");
34776b26852SMarshall Clow     std::basic_string w(w0, 2, 2);
34876b26852SMarshall Clow     ASSERT_SAME_TYPE(decltype(w), std::wstring);
34976b26852SMarshall Clow     assert(w == L"cd");
350f4c1258dSLouis Dionne #endif
35176b26852SMarshall Clow   }
35276b26852SMarshall Clow   { // Testing (15) w/ allocator
35376b26852SMarshall Clow     using ExpectS = std::basic_string<char, std::char_traits<char>, test_allocator<char>>;
35476b26852SMarshall Clow     ExpectS s0("abc");
35576b26852SMarshall Clow     std::basic_string s(s0, 1, 1, test_allocator<char>{4});
35676b26852SMarshall Clow     ASSERT_SAME_TYPE(decltype(s), ExpectS);
35776b26852SMarshall Clow     assert(s == "b");
35876b26852SMarshall Clow 
359f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
36076b26852SMarshall Clow     using ExpectW = std::basic_string<wchar_t, std::char_traits<wchar_t>, test_allocator<wchar_t>>;
36176b26852SMarshall Clow     ExpectW w0(L"abcdef");
36276b26852SMarshall Clow     std::basic_string w(w0, 2, 2, test_allocator<wchar_t>{6});
36376b26852SMarshall Clow     ASSERT_SAME_TYPE(decltype(w), ExpectW);
36476b26852SMarshall Clow     assert(w == L"cd");
365f4c1258dSLouis Dionne #endif
366dd3ba794SEric Fiselier   }
3672df59c50SJF Bastien 
368e85018b7SNikolas Klauser   return true;
369e85018b7SNikolas Klauser }
370e85018b7SNikolas Klauser 
main(int,char **)371e85018b7SNikolas Klauser int main(int, char**)
372e85018b7SNikolas Klauser {
373e85018b7SNikolas Klauser   test();
374e85018b7SNikolas Klauser #if TEST_STD_VER > 17
375*425620ccSNikolas Klauser   static_assert(test());
376e85018b7SNikolas Klauser #endif
377e85018b7SNikolas Klauser 
3782df59c50SJF Bastien   return 0;
379dd3ba794SEric Fiselier }
380