[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / array / at_const.pass.cpp
blob8d625097cf2e329b3dab06333ef4e419af9c9e28
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 // GCC 5 doesn't implement the required constexpr support
14 // UNSUPPORTED: gcc-5
16 #include <array>
17 #include <cassert>
19 #ifndef TEST_HAS_NO_EXCEPTIONS
20 #include <stdexcept>
21 #endif
23 #include "test_macros.h"
25 // std::array is explicitly allowed to be initialized with A a = { init-list };.
26 // Disable the missing braces warning for this reason.
27 #include "disable_missing_braces_warning.h"
30 TEST_CONSTEXPR_CXX14 bool tests()
33 typedef double T;
34 typedef std::array<T, 3> C;
35 C const c = {1, 2, 3.5};
36 typename C::const_reference r1 = c.at(0);
37 assert(r1 == 1);
39 typename C::const_reference r2 = c.at(2);
40 assert(r2 == 3.5);
42 return true;
45 void test_exceptions()
47 #ifndef TEST_HAS_NO_EXCEPTIONS
49 std::array<int, 4> const array = {1, 2, 3, 4};
51 try {
52 TEST_IGNORE_NODISCARD array.at(4);
53 assert(false);
54 } catch (std::out_of_range const&) {
55 // pass
56 } catch (...) {
57 assert(false);
60 try {
61 TEST_IGNORE_NODISCARD array.at(5);
62 assert(false);
63 } catch (std::out_of_range const&) {
64 // pass
65 } catch (...) {
66 assert(false);
69 try {
70 TEST_IGNORE_NODISCARD array.at(6);
71 assert(false);
72 } catch (std::out_of_range const&) {
73 // pass
74 } catch (...) {
75 assert(false);
78 try {
79 using size_type = decltype(array)::size_type;
80 TEST_IGNORE_NODISCARD array.at(static_cast<size_type>(-1));
81 assert(false);
82 } catch (std::out_of_range const&) {
83 // pass
84 } catch (...) {
85 assert(false);
90 std::array<int, 0> array = {};
92 try {
93 TEST_IGNORE_NODISCARD array.at(0);
94 assert(false);
95 } catch (std::out_of_range const&) {
96 // pass
97 } catch (...) {
98 assert(false);
101 #endif
104 int main(int, char**)
106 tests();
107 test_exceptions();
109 #if TEST_STD_VER >= 14
110 static_assert(tests(), "");
111 #endif
112 return 0;