| 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 | // <vector> |
| 10 | |
| 11 | // void clear() noexcept; |
| 12 | |
| 13 | #include <vector> |
| 14 | #include <cassert> |
| 15 | |
| 16 | #include "test_macros.h" |
| 17 | #include "min_allocator.h" |
| 18 | #include "asan_testing.h" |
| 19 | |
| 20 | TEST_CONSTEXPR_CXX20 bool tests() { |
| 21 | { |
| 22 | int a[] = {1, 2, 3}; |
| 23 | std::vector<int> c(a, a + 3); |
| 24 | ASSERT_NOEXCEPT(c.clear()); |
| 25 | c.clear(); |
| 26 | assert(c.empty()); |
| 27 | LIBCPP_ASSERT(c.__invariants()); |
| 28 | LIBCPP_ASSERT(is_contiguous_container_asan_correct(c)); |
| 29 | } |
| 30 | #if TEST_STD_VER >= 11 |
| 31 | { |
| 32 | int a[] = {1, 2, 3}; |
| 33 | std::vector<int, min_allocator<int>> c(a, a + 3); |
| 34 | ASSERT_NOEXCEPT(c.clear()); |
| 35 | c.clear(); |
| 36 | assert(c.empty()); |
| 37 | LIBCPP_ASSERT(c.__invariants()); |
| 38 | LIBCPP_ASSERT(is_contiguous_container_asan_correct(c)); |
| 39 | } |
| 40 | { |
| 41 | int a[] = {1, 2, 3}; |
| 42 | std::vector<int, safe_allocator<int>> c(a, a + 3); |
| 43 | ASSERT_NOEXCEPT(c.clear()); |
| 44 | c.clear(); |
| 45 | assert(c.empty()); |
| 46 | LIBCPP_ASSERT(c.__invariants()); |
| 47 | LIBCPP_ASSERT(is_contiguous_container_asan_correct(c)); |
| 48 | } |
| 49 | #endif |
| 50 | |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | int main(int, char**) { |
| 55 | tests(); |
| 56 | #if TEST_STD_VER > 17 |
| 57 | static_assert(tests()); |
| 58 | #endif |
| 59 | return 0; |
| 60 | } |
| 61 | |