xref: /llvm-project/libcxx/test/libcxx/containers/sequences/vector/assert.back.empty.pass.cpp (revision 58780b811c23df3d928d8452ee21c862dde754a2)
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 // Call back() on empty container.
12 
13 // REQUIRES: has-unix-headers
14 // UNSUPPORTED: c++03
15 // UNSUPPORTED: libcpp-hardening-mode=none
16 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
17 
18 #include <vector>
19 #include <cassert>
20 
21 #include "check_assertion.h"
22 #include "min_allocator.h"
23 
main(int,char **)24 int main(int, char**) {
25   {
26     typedef int T;
27     typedef std::vector<T, min_allocator<T> > C;
28     C c(1);
29     assert(c.back() == 0);
30     c.clear();
31     TEST_LIBCPP_ASSERT_FAILURE(c.back(), "back() called on an empty vector");
32   }
33   {
34     typedef int T;
35     typedef std::vector<T> C;
36     C c(1);
37     assert(c.back() == 0);
38     c.clear();
39     TEST_LIBCPP_ASSERT_FAILURE(c.back(), "back() called on an empty vector");
40   }
41 
42   return 0;
43 }
44