[mlir][acc] Introduce MappableType interface (#122146)
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.cons / initializer_list_assignment.pass.cpp
bloba3491696a4fc8aa1a658e6632a065fc67d7561d8
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <string>
13 // basic_string& operator=(initializer_list<charT> il); // constexpr since C++20
15 #include <string>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "asan_testing.h"
22 // clang-format off
23 template <template <class> class Alloc>
24 TEST_CONSTEXPR_CXX20 void test_string() {
26 typedef std::basic_string<char, std::char_traits<char>, Alloc<char>> S;
27 S s;
28 S& result = (s = {'a', 'b', 'c'});
29 assert(s == "abc");
30 assert(&result == &s);
31 LIBCPP_ASSERT(is_string_asan_correct(s));
32 LIBCPP_ASSERT(is_string_asan_correct(result));
35 typedef std::basic_string<char, std::char_traits<char>, Alloc<char>> S;
36 S s;
37 s = {'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
38 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'};
39 assert(s == "aaaaaaaaaaaaaaaaaaaaaaaa");
40 LIBCPP_ASSERT(is_string_asan_correct(s));
42 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
44 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, Alloc<wchar_t>> S;
45 S s;
46 S& result = (s = {L'a', L'b', L'c'});
47 assert(s == L"abc");
48 assert(&result == &s);
49 LIBCPP_ASSERT(is_string_asan_correct(s));
50 LIBCPP_ASSERT(is_string_asan_correct(result));
53 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, Alloc<wchar_t>> S;
54 S s;
55 S& result = (s = {L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a'});
56 assert(s == L"aaaaaaaaaaaaaaaaaaaaaaaaa");
57 assert(&result == &s);
58 LIBCPP_ASSERT(is_string_asan_correct(s));
59 LIBCPP_ASSERT(is_string_asan_correct(result));
61 #endif
63 // clang-format on
65 TEST_CONSTEXPR_CXX20 bool test() {
66 test_string<std::allocator>();
67 test_string<min_allocator>();
68 test_string<safe_allocator>();
70 return true;
73 int main(int, char**) {
74 test();
75 #if TEST_STD_VER > 17
76 static_assert(test());
77 #endif
79 return 0;