|
| 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 | +// Test hardening assertions for std::forward_list. |
| 12 | + |
| 13 | +// REQUIRES: has-unix-headers |
| 14 | +// REQUIRES: libcpp-hardening-mode={{extensive|debug}} |
| 15 | +// UNSUPPORTED: c++03 |
| 16 | +// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing |
| 17 | + |
| 18 | +#include <forward_list> |
| 19 | + |
| 20 | +#include "check_assertion.h" |
| 21 | + |
| 22 | +int main(int, char**) { |
| 23 | + { // Default-constructed list. |
| 24 | + std::forward_list<int> c; |
| 25 | + const auto& const_c = c; |
| 26 | + TEST_LIBCPP_ASSERT_FAILURE(c.front(), "forward_list::front called on an empty list"); |
| 27 | + TEST_LIBCPP_ASSERT_FAILURE(const_c.front(), "forward_list::front called on an empty list"); |
| 28 | + TEST_LIBCPP_ASSERT_FAILURE(c.pop_front(), "forward_list::pop_front called on an empty list"); |
| 29 | + } |
| 30 | + |
| 31 | + { // Non-empty list becomes empty. |
| 32 | + std::forward_list<int> c; |
| 33 | + const auto& const_c = c; |
| 34 | + c.push_front(1); |
| 35 | + |
| 36 | + (void)c.front(); // Check that there's no assertion on valid access. |
| 37 | + (void)const_c.front(); // Check that there's no assertion on valid access. |
| 38 | + c.pop_front(); |
| 39 | + TEST_LIBCPP_ASSERT_FAILURE(c.pop_front(), "forward_list::pop_front called on an empty list"); |
| 40 | + TEST_LIBCPP_ASSERT_FAILURE(c.front(), "forward_list::front called on an empty list"); |
| 41 | + TEST_LIBCPP_ASSERT_FAILURE(const_c.front(), "forward_list::front called on an empty list"); |
| 42 | + } |
| 43 | + |
| 44 | + return 0; |
| 45 | +} |
0 commit comments