[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / sequences / array / at.pass.cpp
blob90b5684b1e567d198ff9183d3caa3d165c7fc834
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 // <array>
11 // reference at (size_type); // constexpr in C++17
13 #include <array>
14 #include <cassert>
16 #ifndef TEST_HAS_NO_EXCEPTIONS
17 #include <stdexcept>
18 #endif
20 #include "test_macros.h"
22 TEST_CONSTEXPR_CXX17 bool tests()
25 typedef double T;
26 typedef std::array<T, 3> C;
27 C c = {1, 2, 3.5};
28 typename C::reference r1 = c.at(0);
29 assert(r1 == 1);
30 r1 = 5.5;
31 assert(c[0] == 5.5);
33 typename C::reference r2 = c.at(2);
34 assert(r2 == 3.5);
35 r2 = 7.5;
36 assert(c[2] == 7.5);
38 return true;
41 void test_exceptions()
43 #ifndef TEST_HAS_NO_EXCEPTIONS
45 std::array<int, 4> array = {1, 2, 3, 4};
47 try {
48 TEST_IGNORE_NODISCARD array.at(4);
49 assert(false);
50 } catch (std::out_of_range const&) {
51 // pass
52 } catch (...) {
53 assert(false);
56 try {
57 TEST_IGNORE_NODISCARD array.at(5);
58 assert(false);
59 } catch (std::out_of_range const&) {
60 // pass
61 } catch (...) {
62 assert(false);
65 try {
66 TEST_IGNORE_NODISCARD array.at(6);
67 assert(false);
68 } catch (std::out_of_range const&) {
69 // pass
70 } catch (...) {
71 assert(false);
74 try {
75 using size_type = decltype(array)::size_type;
76 TEST_IGNORE_NODISCARD array.at(static_cast<size_type>(-1));
77 assert(false);
78 } catch (std::out_of_range const&) {
79 // pass
80 } catch (...) {
81 assert(false);
86 std::array<int, 0> array = {};
88 try {
89 TEST_IGNORE_NODISCARD array.at(0);
90 assert(false);
91 } catch (std::out_of_range const&) {
92 // pass
93 } catch (...) {
94 assert(false);
97 #endif
100 int main(int, char**)
102 tests();
103 test_exceptions();
105 #if TEST_STD_VER >= 17
106 static_assert(tests(), "");
107 #endif
108 return 0;