| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03 |
| 10 | |
| 11 | // <string> |
| 12 | |
| 13 | // iterator insert(const_iterator p, initializer_list<charT> il); // constexpr since C++20 |
| 14 | |
| 15 | #include <string> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "min_allocator.h" |
| 20 | #include "asan_testing.h" |
| 21 | |
| 22 | template <class S> |
| 23 | TEST_CONSTEXPR_CXX20 void test_string() { |
| 24 | S s("123456" ); |
| 25 | typename S::iterator i = s.insert(s.begin() + 3, {'a', 'b', 'c'}); |
| 26 | assert(i - s.begin() == 3); |
| 27 | assert(s == "123abc456" ); |
| 28 | LIBCPP_ASSERT(is_string_asan_correct(s)); |
| 29 | typename S::iterator j = s.insert(s.begin() + 6, {'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', |
| 30 | 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'}); |
| 31 | assert(j - s.begin() == 6); |
| 32 | assert(s == "123abcaaaaaaaaaaaaaaaaaaaaaaaaa456" ); |
| 33 | LIBCPP_ASSERT(is_string_asan_correct(s)); |
| 34 | } |
| 35 | |
| 36 | TEST_CONSTEXPR_CXX20 bool test() { |
| 37 | test_string<std::string>(); |
| 38 | test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); |
| 39 | test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char> > >(); |
| 40 | |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | int main(int, char**) { |
| 45 | test(); |
| 46 | #if TEST_STD_VER > 17 |
| 47 | static_assert(test()); |
| 48 | #endif |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |