brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · f525122 Raw
56 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <string>10 11// void pop_back(); // constexpr since C++2012 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 >= 1141  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#endif44 45  return true;46}47 48int main(int, char**) {49  test();50#if TEST_STD_VER > 1751  static_assert(test());52#endif53 54  return 0;55}56