[SLP] Make getSameOpcode support different instructions if they have same semantics...
[llvm-project.git] / libcxx / test / std / containers / sequences / array / at_const.pass.cpp
blob2ddd5a03a6c672670a5640a52f5930016c16ef6e
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 // const_reference at (size_type) const; // constexpr in C++14
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_CXX14 bool tests()
25 typedef double T;
26 typedef std::array<T, 3> C;
27 C const c = {1, 2, 3.5};
28 typename C::const_reference r1 = c.at(0);
29 assert(r1 == 1);
31 typename C::const_reference r2 = c.at(2);
32 assert(r2 == 3.5);
34 return true;
37 void test_exceptions()
39 #ifndef TEST_HAS_NO_EXCEPTIONS
41 std::array<int, 4> const array = {1, 2, 3, 4};
43 try {
44 TEST_IGNORE_NODISCARD array.at(4);
45 assert(false);
46 } catch (std::out_of_range const&) {
47 // pass
48 } catch (...) {
49 assert(false);
52 try {
53 TEST_IGNORE_NODISCARD array.at(5);
54 assert(false);
55 } catch (std::out_of_range const&) {
56 // pass
57 } catch (...) {
58 assert(false);
61 try {
62 TEST_IGNORE_NODISCARD array.at(6);
63 assert(false);
64 } catch (std::out_of_range const&) {
65 // pass
66 } catch (...) {
67 assert(false);
70 try {
71 using size_type = decltype(array)::size_type;
72 TEST_IGNORE_NODISCARD array.at(static_cast<size_type>(-1));
73 assert(false);
74 } catch (std::out_of_range const&) {
75 // pass
76 } catch (...) {
77 assert(false);
82 std::array<int, 0> array = {};
84 try {
85 TEST_IGNORE_NODISCARD array.at(0);
86 assert(false);
87 } catch (std::out_of_range const&) {
88 // pass
89 } catch (...) {
90 assert(false);
93 #endif
96 int main(int, char**)
98 tests();
99 test_exceptions();
101 #if TEST_STD_VER >= 14
102 static_assert(tests(), "");
103 #endif
104 return 0;