xref: /llvm-project/libcxx/test/libcxx/numerics/numarray/class.slice.array/assert.get.pass.cpp (revision 5ca2777c69f8708d583e230c56ac7f5f6376fb40)
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 // REQUIRES: has-unix-headers
10 // UNSUPPORTED: c++03
11 // UNSUPPORTED: libcpp-hardening-mode=none
12 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
13 
14 // <valarray>
15 
16 // template<class T> class slice_array;
17 
18 // T __get(size_t i); // where i is out of bounds
19 
20 #include <valarray>
21 
22 #include "check_assertion.h"
23 
main(int,char **)24 int main(int, char**) {
25   unsigned input[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
26   const unsigned N = sizeof(input) / sizeof(input[0]);
27 
28   std::valarray<unsigned> array(input, N);
29 
30   {
31     std::slice_array<unsigned> result = array[std::slice(0, 0, 0)];
32     TEST_LIBCPP_ASSERT_FAILURE(result.__get(0), "slice_array.__get() index out of bounds");
33   }
34   {
35     std::slice_array<unsigned> result = array[std::slice(0, N, 1)];
36     TEST_LIBCPP_ASSERT_FAILURE(result.__get(N), "slice_array.__get() index out of bounds");
37   }
38   {
39     std::slice_array<unsigned> result = array[std::slice(3, 2, 2)];
40     TEST_LIBCPP_ASSERT_FAILURE(result.__get(2), "slice_array.__get() index out of bounds");
41   }
42 
43   {
44     std::slice_array<unsigned> result = array[std::slice(1, 3, 4)];
45     TEST_LIBCPP_ASSERT_FAILURE(result.__get(3), "slice_array.__get() index out of bounds");
46   }
47 
48   return 0;
49 }
50