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 // const_reference at (size_type) const; // constexpr in C++14
13 // GCC 5 doesn't implement the required constexpr support
19 #ifndef TEST_HAS_NO_EXCEPTIONS
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()
34 typedef std::array
<T
, 3> C
;
35 C
const c
= {1, 2, 3.5};
36 typename
C::const_reference r1
= c
.at(0);
39 typename
C::const_reference r2
= c
.at(2);
45 void test_exceptions()
47 #ifndef TEST_HAS_NO_EXCEPTIONS
49 std::array
<int, 4> const array
= {1, 2, 3, 4};
52 TEST_IGNORE_NODISCARD array
.at(4);
54 } catch (std::out_of_range
const&) {
61 TEST_IGNORE_NODISCARD array
.at(5);
63 } catch (std::out_of_range
const&) {
70 TEST_IGNORE_NODISCARD array
.at(6);
72 } catch (std::out_of_range
const&) {
79 using size_type
= decltype(array
)::size_type
;
80 TEST_IGNORE_NODISCARD array
.at(static_cast<size_type
>(-1));
82 } catch (std::out_of_range
const&) {
90 std::array
<int, 0> array
= {};
93 TEST_IGNORE_NODISCARD array
.at(0);
95 } catch (std::out_of_range
const&) {
104 int main(int, char**)
109 #if TEST_STD_VER >= 14
110 static_assert(tests(), "");