Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.cons / char_assignment.pass.cpp
blob3cffc82e94835263a94d77b951cbb419c860483b
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>& operator=(charT c); // constexpr since C++20
13 #include <string>
14 #include <cassert>
16 #include "test_macros.h"
17 #include "min_allocator.h"
19 template <class S>
20 TEST_CONSTEXPR_CXX20 void test(S s1, typename S::value_type s2) {
21 typedef typename S::traits_type T;
22 s1 = s2;
23 LIBCPP_ASSERT(s1.__invariants());
24 assert(s1.size() == 1);
25 assert(T::eq(s1[0], s2));
26 assert(s1.capacity() >= s1.size());
29 template <class S>
30 TEST_CONSTEXPR_CXX20 void test_string() {
31 test(S(), 'a');
32 test(S("1"), 'a');
33 test(S("123456789"), 'a');
34 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
37 TEST_CONSTEXPR_CXX20 bool test() {
38 test_string<std::string>();
39 #if TEST_STD_VER >= 11
40 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
41 #endif
43 return true;
46 int main(int, char**) {
47 test();
48 #if TEST_STD_VER > 17
49 static_assert(test());
50 #endif
52 return 0;