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// <string>
10
11// void pop_back(); // constexpr since C++20
12
13#include <string>
14#include <cassert>
15
16#include "test_macros.h"
17#include "min_allocator.h"
18#include "asan_testing.h"
19
20template <class S>
21TEST_CONSTEXPR_CXX20 void test(S s, S expected) {
22 s.pop_back();
23 LIBCPP_ASSERT(s.__invariants());
24 assert(s[s.size()] == typename S::value_type());
25 assert(s == expected);
26 LIBCPP_ASSERT(is_string_asan_correct(s));
27}
28
29template <class S>
30TEST_CONSTEXPR_CXX20 void test_string() {
31 test(S("abcde"), S("abcd"));
32 test(S("abcdefghij"), S("abcdefghi"));
33 test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrs"));
34 test(S("abcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrst"),
35 S("abcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrstabcdefghijklmnopqrs"));
36}
37
38TEST_CONSTEXPR_CXX20 bool test() {
39 test_string<std::string>();
40#if TEST_STD_VER >= 11
41 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
42 test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
43#endif
44
45 return true;
46}
47
48int main(int, char**) {
49 test();
50#if TEST_STD_VER > 17
51 static_assert(test());
52#endif
53
54 return 0;
55}
56

source code of libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp