[SLP] Make getSameOpcode support different instructions if they have same semantics...
[llvm-project.git] / libcxx / test / std / containers / sequences / array / assert.indexing.pass.cpp
blobea0ffce3b3007d74402b4033bafb27907a98e368
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 //===----------------------------------------------------------------------===//
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
14 // <array>
16 // Test that operator[] triggers an assertion when accessing the array out-of-bounds.
18 #include <array>
20 #include "check_assertion.h"
22 int main(int, char**) {
23 // Check with an empty array
26 using Array = std::array<int, 0>;
27 Array c = {};
28 Array const& cc = c;
29 TEST_LIBCPP_ASSERT_FAILURE(c[0], "cannot call array<T, 0>::operator[] on a zero-sized array");
30 TEST_LIBCPP_ASSERT_FAILURE(c[1], "cannot call array<T, 0>::operator[] on a zero-sized array");
31 TEST_LIBCPP_ASSERT_FAILURE(cc[0], "cannot call array<T, 0>::operator[] on a zero-sized array");
32 TEST_LIBCPP_ASSERT_FAILURE(cc[1], "cannot call array<T, 0>::operator[] on a zero-sized array");
35 using Array = std::array<const int, 0>;
36 Array c = {{}};
37 Array const& cc = c;
38 TEST_LIBCPP_ASSERT_FAILURE(c[0], "cannot call array<T, 0>::operator[] on a zero-sized array");
39 TEST_LIBCPP_ASSERT_FAILURE(c[1], "cannot call array<T, 0>::operator[] on a zero-sized array");
40 TEST_LIBCPP_ASSERT_FAILURE(cc[0], "cannot call array<T, 0>::operator[] on a zero-sized array");
41 TEST_LIBCPP_ASSERT_FAILURE(cc[1], "cannot call array<T, 0>::operator[] on a zero-sized array");
45 // Check with non-empty arrays
48 using Array = std::array<int, 1>;
49 Array c = {};
50 Array const& cc = c;
51 TEST_LIBCPP_ASSERT_FAILURE(c[2], "out-of-bounds access in std::array<T, N>");
52 TEST_LIBCPP_ASSERT_FAILURE(cc[2], "out-of-bounds access in std::array<T, N>");
55 using Array = std::array<const int, 1>;
56 Array c = {{}};
57 Array const& cc = c;
58 TEST_LIBCPP_ASSERT_FAILURE(c[2], "out-of-bounds access in std::array<T, N>");
59 TEST_LIBCPP_ASSERT_FAILURE(cc[2], "out-of-bounds access in std::array<T, N>");
63 using Array = std::array<int, 5>;
64 Array c = {};
65 Array const& cc = c;
66 TEST_LIBCPP_ASSERT_FAILURE(c[99], "out-of-bounds access in std::array<T, N>");
67 TEST_LIBCPP_ASSERT_FAILURE(cc[99], "out-of-bounds access in std::array<T, N>");
70 using Array = std::array<const int, 5>;
71 Array c = {{}};
72 Array const& cc = c;
73 TEST_LIBCPP_ASSERT_FAILURE(c[99], "out-of-bounds access in std::array<T, N>");
74 TEST_LIBCPP_ASSERT_FAILURE(cc[99], "out-of-bounds access in std::array<T, N>");
78 return 0;