Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.cons / initializer_list_assignment.pass.cpp
blob88597daba121ac476f6259db18eaf7a8b5969cae
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 // UNSUPPORTED: c++03
11 // <string>
13 // basic_string& operator=(initializer_list<charT> il); // constexpr since C++20
15 #include <string>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "min_allocator.h"
21 // clang-format off
22 template <template <class> class Alloc>
23 TEST_CONSTEXPR_CXX20 void test_string() {
25 typedef std::basic_string<char, std::char_traits<char>, Alloc<char>> S;
26 S s;
27 S& result = (s = {'a', 'b', 'c'});
28 assert(s == "abc");
29 assert(&result == &s);
31 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
33 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, Alloc<wchar_t>> S;
34 S s;
35 S& result = (s = {L'a', L'b', L'c'});
36 assert(s == L"abc");
37 assert(&result == &s);
39 #endif
41 // clang-format on
43 TEST_CONSTEXPR_CXX20 bool test() {
44 test_string<std::allocator>();
45 test_string<min_allocator>();
47 return true;
50 int main(int, char**) {
51 test();
52 #if TEST_STD_VER > 17
53 static_assert(test());
54 #endif
56 return 0;