[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / array / indexing.pass.cpp
blob6b5d8486fda22488021955e6173d1a1c62ab1031
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 operator[](size_type); // constexpr in C++17
12 // Libc++ marks it as noexcept
14 #include <array>
15 #include <cassert>
17 #include "test_macros.h"
19 // std::array is explicitly allowed to be initialized with A a = { init-list };.
20 // Disable the missing braces warning for this reason.
21 #include "disable_missing_braces_warning.h"
24 TEST_CONSTEXPR_CXX17 bool tests()
27 typedef double T;
28 typedef std::array<T, 3> C;
29 C c = {1, 2, 3.5};
30 LIBCPP_ASSERT_NOEXCEPT(c[0]);
31 ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
32 C::reference r1 = c[0];
33 assert(r1 == 1);
34 r1 = 5.5;
35 assert(c.front() == 5.5);
37 C::reference r2 = c[2];
38 assert(r2 == 3.5);
39 r2 = 7.5;
40 assert(c.back() == 7.5);
43 // Test operator[] "works" on zero sized arrays
46 typedef double T;
47 typedef std::array<T, 0> C;
48 C c = {};
49 LIBCPP_ASSERT_NOEXCEPT(c[0]);
50 ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
51 if (c.size() > (0)) { // always false
52 C::reference r = c[0];
53 (void)r;
57 typedef double T;
58 typedef std::array<const T, 0> C;
59 C c = {};
60 LIBCPP_ASSERT_NOEXCEPT(c[0]);
61 ASSERT_SAME_TYPE(C::reference, decltype(c[0]));
62 if (c.size() > (0)) { // always false
63 C::reference r = c[0];
64 (void)r;
69 return true;
72 int main(int, char**)
74 tests();
75 #if TEST_STD_VER >= 17
76 static_assert(tests(), "");
77 #endif
78 return 0;