| 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 | // <forward_list> |
| 10 | |
| 11 | // void clear() noexcept; // constexpr since C++26 |
| 12 | |
| 13 | #include <forward_list> |
| 14 | #include <cassert> |
| 15 | #include <iterator> |
| 16 | |
| 17 | #include "test_macros.h" |
| 18 | #include "../../../NotConstructible.h" |
| 19 | #include "min_allocator.h" |
| 20 | |
| 21 | TEST_CONSTEXPR_CXX26 bool test() { |
| 22 | { |
| 23 | typedef NotConstructible T; |
| 24 | typedef std::forward_list<T> C; |
| 25 | C c; |
| 26 | ASSERT_NOEXCEPT(c.clear()); |
| 27 | c.clear(); |
| 28 | assert(std::distance(c.begin(), c.end()) == 0); |
| 29 | } |
| 30 | { |
| 31 | typedef int T; |
| 32 | typedef std::forward_list<T> C; |
| 33 | const T t[] = {0, 1, 2, 3, 4}; |
| 34 | C c(std::begin(t), std::end(t)); |
| 35 | |
| 36 | ASSERT_NOEXCEPT(c.clear()); |
| 37 | c.clear(); |
| 38 | assert(std::distance(c.begin(), c.end()) == 0); |
| 39 | |
| 40 | c.clear(); |
| 41 | assert(std::distance(c.begin(), c.end()) == 0); |
| 42 | } |
| 43 | #if TEST_STD_VER >= 11 |
| 44 | { |
| 45 | typedef NotConstructible T; |
| 46 | typedef std::forward_list<T, min_allocator<T>> C; |
| 47 | C c; |
| 48 | ASSERT_NOEXCEPT(c.clear()); |
| 49 | c.clear(); |
| 50 | assert(std::distance(c.begin(), c.end()) == 0); |
| 51 | } |
| 52 | { |
| 53 | typedef int T; |
| 54 | typedef std::forward_list<T, min_allocator<T>> C; |
| 55 | const T t[] = {0, 1, 2, 3, 4}; |
| 56 | C c(std::begin(t), std::end(t)); |
| 57 | |
| 58 | ASSERT_NOEXCEPT(c.clear()); |
| 59 | c.clear(); |
| 60 | assert(std::distance(c.begin(), c.end()) == 0); |
| 61 | |
| 62 | c.clear(); |
| 63 | assert(std::distance(c.begin(), c.end()) == 0); |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | int main(int, char**) { |
| 71 | assert(test()); |
| 72 | #if TEST_STD_VER >= 26 |
| 73 | static_assert(test()); |
| 74 | #endif |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |