[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / array / indexing_const.pass.cpp
blob3f34dfe7dd325a24defbd868a2ba28b162f547ed
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 operator[](size_type) const; // constexpr in C++14
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_CXX14 bool tests()
27 typedef double T;
28 typedef std::array<T, 3> C;
29 C const c = {1, 2, 3.5};
30 LIBCPP_ASSERT_NOEXCEPT(c[0]);
31 ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
32 C::const_reference r1 = c[0];
33 assert(r1 == 1);
34 C::const_reference r2 = c[2];
35 assert(r2 == 3.5);
37 // Test operator[] "works" on zero sized arrays
40 typedef double T;
41 typedef std::array<T, 0> C;
42 C const c = {};
43 LIBCPP_ASSERT_NOEXCEPT(c[0]);
44 ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
45 if (c.size() > (0)) { // always false
46 C::const_reference r = c[0];
47 (void)r;
51 typedef double T;
52 typedef std::array<T const, 0> C;
53 C const c = {};
54 LIBCPP_ASSERT_NOEXCEPT(c[0]);
55 ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
56 if (c.size() > (0)) { // always false
57 C::const_reference r = c[0];
58 (void)r;
63 return true;
66 int main(int, char**)
68 tests();
69 #if TEST_STD_VER >= 14
70 static_assert(tests(), "");
71 #endif
72 return 0;