xref: /llvm-project/libcxx/test/std/strings/basic.string/string.cons/brace_assignment.pass.cpp (revision 425620ccdd47e56b59512913cdc71e116f951e4e)
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 
21 TEST_CONSTEXPR_CXX20 bool test() {
22   // Test that assignment from {} and {ptr, len} are allowed and are not
23   // ambiguous.
24   {
25     std::string s = "hello world";
26     s = {};
27     assert(s.empty());
28   }
29   {
30     std::string s = "hello world";
31     s = {"abc", 2};
32     assert(s == "ab");
33   }
34 
35   return true;
36 }
37 
38 int main(int, char**)
39 {
40   test();
41 #if TEST_STD_VER > 17
42   static_assert(test());
43 #endif
44 
45   return 0;
46 }
47