[SLP] Make getSameOpcode support different instructions if they have same semantics...
[llvm-project.git] / libcxx / test / std / containers / sequences / array / indexing_const.pass.cpp
blobce6f8bb59aac83ceb589a873adbca56f1c2899af
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 TEST_CONSTEXPR_CXX14 bool tests()
22 typedef double T;
23 typedef std::array<T, 3> C;
24 C const c = {1, 2, 3.5};
25 LIBCPP_ASSERT_NOEXCEPT(c[0]);
26 ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
27 C::const_reference r1 = c[0];
28 assert(r1 == 1);
29 C::const_reference r2 = c[2];
30 assert(r2 == 3.5);
32 // Test operator[] "works" on zero sized arrays
35 typedef double T;
36 typedef std::array<T, 0> C;
37 C const c = {};
38 LIBCPP_ASSERT_NOEXCEPT(c[0]);
39 ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
40 if (c.size() > (0)) { // always false
41 C::const_reference r = c[0];
42 (void)r;
46 typedef double T;
47 typedef std::array<T const, 0> C;
48 C const c = {};
49 LIBCPP_ASSERT_NOEXCEPT(c[0]);
50 ASSERT_SAME_TYPE(C::const_reference, decltype(c[0]));
51 if (c.size() > (0)) { // always false
52 C::const_reference r = c[0];
53 (void)r;
58 return true;
61 int main(int, char**)
63 tests();
64 #if TEST_STD_VER >= 14
65 static_assert(tests(), "");
66 #endif
67 return 0;