64 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 clear(); // 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) {22 s.clear();23 assert(s.size() == 0);24 LIBCPP_ASSERT(is_string_asan_correct(s));25}26 27template <class S>28TEST_CONSTEXPR_CXX20 void test_string() {29 S s;30 test(s);31 LIBCPP_ASSERT(is_string_asan_correct(s));32 33 s.assign(10, 'a');34 s.erase(5);35 LIBCPP_ASSERT(is_string_asan_correct(s));36 test(s);37 LIBCPP_ASSERT(is_string_asan_correct(s));38 39 s.assign(100, 'a');40 s.erase(50);41 LIBCPP_ASSERT(is_string_asan_correct(s));42 test(s);43 LIBCPP_ASSERT(is_string_asan_correct(s));44}45 46TEST_CONSTEXPR_CXX20 bool test() {47 test_string<std::string>();48#if TEST_STD_VER >= 1149 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();50 test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();51#endif52 53 return true;54}55 56int main(int, char**) {57 test();58#if TEST_STD_VER > 1759 static_assert(test());60#endif61 62 return 0;63}64