Revert "[AMDGPU][CodeGen] Do not backtrace invalid -regalloc param (#119687)"
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.modifiers / string_assign / pointer.pass.cpp
blob0d5c269d30df47fea19754a3860b831e6ef18491
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 // <string>
11 // basic_string<charT,traits,Allocator>& assign(const charT* s); // constexpr since C++20
13 #include <string>
14 #include <stdexcept>
15 #include <cassert>
17 #include "test_macros.h"
18 #include "min_allocator.h"
19 #include "asan_testing.h"
21 template <class S>
22 TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, S expected) {
23 s.assign(str);
24 LIBCPP_ASSERT(s.__invariants());
25 assert(s == expected);
26 LIBCPP_ASSERT(is_string_asan_correct(s));
29 template <class S>
30 TEST_CONSTEXPR_CXX20 void test_string() {
31 test(S(), "", S());
32 test(S(), "12345", S("12345"));
33 test(S(), "12345678901234567890", S("12345678901234567890"));
35 test(S("12345"), "", S());
36 test(S("12345"), "12345", S("12345"));
37 test(S("12345"), "1234567890", S("1234567890"));
39 test(S("12345678901234567890"), "", S());
40 test(S("12345678901234567890"), "12345", S("12345"));
41 test(S("12345678901234567890"), "12345678901234567890", S("12345678901234567890"));
43 // Starting from long string (no SSO)
44 test(S("1234512345678901234567890"), "", S());
45 test(S("1234512345678901234567890"), "12345", S("12345"));
46 test(S("1234512345678901234567890"), "12345678901234567890", S("12345678901234567890"));
49 TEST_CONSTEXPR_CXX20 bool test() {
50 test_string<std::string>();
51 #if TEST_STD_VER >= 11
52 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
53 test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
54 #endif
56 { // test assignment to self
57 typedef std::string S;
58 S s_short = "123/";
59 S s_long = "Lorem ipsum dolor sit amet, consectetur/";
61 s_short.assign(s_short.c_str());
62 assert(s_short == "123/");
63 s_short.assign(s_short.c_str() + 2);
64 assert(s_short == "3/");
66 s_long.assign(s_long.c_str() + 30);
67 assert(s_long == "nsectetur/");
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;