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(initializer_list<charT> il, const Allocator& a = Allocator()); // constexpr since C++20
14
15#include <string>
16#include <cassert>
17
18#include "test_macros.h"
19#include "test_allocator.h"
20#include "min_allocator.h"
21#include "asan_testing.h"
22
23// clang-format off
24template <template <class> class Alloc>
25TEST_CONSTEXPR_CXX20 void test_string() {
26 {
27 std::basic_string<char, std::char_traits<char>, Alloc<char> > s = {'a', 'b', 'c'};
28 assert(s == "abc");
29 LIBCPP_ASSERT(is_string_asan_correct(s));
30 }
31 {
32 std::basic_string<char, std::char_traits<char>, Alloc<char> > s = {'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'};
33 assert(s == "aaaaaaaaaaaaaaaaaaaaaaaaa");
34 LIBCPP_ASSERT(is_string_asan_correct(s));
35 }
36#ifndef TEST_HAS_NO_WIDE_CHARACTERS
37 {
38 std::basic_string<wchar_t, std::char_traits<wchar_t>, Alloc<wchar_t> > s = {L'a', L'b', L'c'};
39 assert(s == L"abc");
40 LIBCPP_ASSERT(is_string_asan_correct(s));
41 }
42 {
43 std::basic_string<wchar_t, std::char_traits<wchar_t>, Alloc<wchar_t> > s = {L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a', L'a'};
44 assert(s == L"aaaaaaaaaaaaaaaaaaaaaaaaa");
45 LIBCPP_ASSERT(is_string_asan_correct(s));
46 }
47#endif
48}
49// clang-format on
50
51TEST_CONSTEXPR_CXX20 bool test() {
52 test_string<std::allocator>();
53 test_string<min_allocator>();
54 test_string<safe_allocator>();
55
56 return true;
57}
58
59int main(int, char**) {
60 test();
61#if TEST_STD_VER > 17
62 static_assert(test());
63#endif
64
65 return 0;
66}
67

source code of libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp