1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // reference operator[](size_type); // constexpr in C++17
12 // Libc++ marks it as noexcept
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()
28 typedef std::array
<T
, 3> C
;
30 LIBCPP_ASSERT_NOEXCEPT(c
[0]);
31 ASSERT_SAME_TYPE(C::reference
, decltype(c
[0]));
32 C::reference r1
= c
[0];
35 assert(c
.front() == 5.5);
37 C::reference r2
= c
[2];
40 assert(c
.back() == 7.5);
43 // Test operator[] "works" on zero sized arrays
47 typedef std::array
<T
, 0> 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];
58 typedef std::array
<const T
, 0> 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];
75 #if TEST_STD_VER >= 17
76 static_assert(tests(), "");