Marshall Clow | 8bf1f08 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Asiri Rathnayake | f520c14 | 2015-11-10 11:41:22 +0000 | [diff] [blame] | 10 | // XFAIL: libcpp-no-exceptions |
Marshall Clow | 8bf1f08 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 11 | // <array> |
| 12 | |
| 13 | // reference operator[] (size_type) |
| 14 | // const_reference operator[] (size_type); // constexpr in C++14 |
| 15 | // reference at (size_type) |
| 16 | // const_reference at (size_type); // constexpr in C++14 |
| 17 | |
| 18 | #include <array> |
| 19 | #include <cassert> |
| 20 | |
Eric Fiselier | 2decfad | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 21 | #include "test_macros.h" |
| 22 | |
Eric Fiselier | b4e2e7a | 2015-10-01 07:05:38 +0000 | [diff] [blame] | 23 | // std::array is explicitly allowed to be initialized with A a = { init-list };. |
| 24 | // Disable the missing braces warning for this reason. |
| 25 | #include "disable_missing_braces_warning.h" |
Eric Fiselier | 2decfad | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 26 | |
Marshall Clow | 8bf1f08 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 27 | int main() |
| 28 | { |
| 29 | { |
| 30 | typedef double T; |
| 31 | typedef std::array<T, 3> C; |
| 32 | C c = {1, 2, 3.5}; |
| 33 | C::reference r1 = c.at(0); |
| 34 | assert(r1 == 1); |
| 35 | r1 = 5.5; |
| 36 | assert(c.front() == 5.5); |
Eric Fiselier | 2decfad | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 37 | |
Marshall Clow | 8bf1f08 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 38 | C::reference r2 = c.at(2); |
| 39 | assert(r2 == 3.5); |
| 40 | r2 = 7.5; |
| 41 | assert(c.back() == 7.5); |
| 42 | |
| 43 | try { (void) c.at(3); } |
| 44 | catch (const std::out_of_range &) {} |
| 45 | } |
| 46 | { |
| 47 | typedef double T; |
| 48 | typedef std::array<T, 3> C; |
| 49 | const C c = {1, 2, 3.5}; |
| 50 | C::const_reference r1 = c.at(0); |
| 51 | assert(r1 == 1); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 52 | |
Marshall Clow | 8bf1f08 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 53 | C::const_reference r2 = c.at(2); |
| 54 | assert(r2 == 3.5); |
| 55 | |
| 56 | try { (void) c.at(3); } |
| 57 | catch (const std::out_of_range &) {} |
| 58 | } |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 59 | |
Eric Fiselier | 2decfad | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 60 | #if TEST_STD_VER > 11 |
Marshall Clow | 8bf1f08 | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 61 | { |
| 62 | typedef double T; |
| 63 | typedef std::array<T, 3> C; |
| 64 | constexpr C c = {1, 2, 3.5}; |
| 65 | |
| 66 | constexpr T t1 = c.at(0); |
| 67 | static_assert (t1 == 1, ""); |
| 68 | |
| 69 | constexpr T t2 = c.at(2); |
| 70 | static_assert (t2 == 3.5, ""); |
| 71 | } |
| 72 | #endif |
| 73 | |
| 74 | } |