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 // basic_string<charT,traits,Allocator>&
14 // operator=(basic_string<charT,traits,Allocator>&& str); // constexpr since C++20
15
16 #include <string>
17 #include <cassert>
18
19 #include "test_macros.h"
20 #include "asan_testing.h"
21
test()22 TEST_CONSTEXPR_CXX20 bool test() {
23 // Test that assignment from {} and {ptr, len} are allowed and are not
24 // ambiguous.
25 {
26 std::string s = "hello world";
27 s = {};
28 assert(s.empty());
29 LIBCPP_ASSERT(is_string_asan_correct(s));
30 }
31 {
32 std::string s = "hello world";
33 s = {"abc", 2};
34 assert(s == "ab");
35 LIBCPP_ASSERT(is_string_asan_correct(s));
36 }
37 {
38 std::string s = "hello world";
39 s = {"It'sALongString!NoSSO!qwertyuiop", 30};
40 assert(s == "It'sALongString!NoSSO!qwertyui");
41 LIBCPP_ASSERT(is_string_asan_correct(s));
42 }
43 {
44 std::string s = "Hello world! Hello world! Hello world! Hello world! Hello world!";
45 s = {"It'sALongString!NoSSO!qwertyuiop", 30};
46 assert(s == "It'sALongString!NoSSO!qwertyui");
47 LIBCPP_ASSERT(is_string_asan_correct(s));
48 }
49 {
50 std::string s = "Hello world! Hello world! Hello world! Hello world! Hello world!";
51 s = {"abc", 2};
52 assert(s == "ab");
53 LIBCPP_ASSERT(is_string_asan_correct(s));
54 }
55 {
56 std::string s = "Hello world! Hello world! Hello world! Hello world! Hello world!";
57 s = {"abc", 0};
58 assert(s == "");
59 LIBCPP_ASSERT(is_string_asan_correct(s));
60 }
61
62 return true;
63 }
64
main(int,char **)65 int main(int, char**) {
66 test();
67 #if TEST_STD_VER > 17
68 static_assert(test());
69 #endif
70
71 return 0;
72 }
73