Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <array> |
| 10 | |
| 11 | // bool operator==(array<T, N> const&, array<T, N> const&); |
| 12 | // bool operator!=(array<T, N> const&, array<T, N> const&); |
| 13 | // bool operator<(array<T, N> const&, array<T, N> const&); |
| 14 | // bool operator<=(array<T, N> const&, array<T, N> const&); |
| 15 | // bool operator>(array<T, N> const&, array<T, N> const&); |
| 16 | // bool operator>=(array<T, N> const&, array<T, N> const&); |
| 17 | |
| 18 | |
| 19 | #include <array> |
| 20 | #include <vector> |
| 21 | #include <cassert> |
| 22 | |
| 23 | #include "test_macros.h" |
| 24 | |
| 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" |
| 28 | |
| 29 | template <class Array> |
| 30 | void test_compare(const Array& LHS, const Array& RHS) { |
| 31 | typedef std::vector<typename Array::value_type> Vector; |
| 32 | const Vector LHSV(LHS.begin(), LHS.end()); |
| 33 | const Vector RHSV(RHS.begin(), RHS.end()); |
| 34 | assert((LHS == RHS) == (LHSV == RHSV)); |
| 35 | assert((LHS != RHS) == (LHSV != RHSV)); |
| 36 | assert((LHS < RHS) == (LHSV < RHSV)); |
| 37 | assert((LHS <= RHS) == (LHSV <= RHSV)); |
| 38 | assert((LHS > RHS) == (LHSV > RHSV)); |
| 39 | assert((LHS >= RHS) == (LHSV >= RHSV)); |
| 40 | } |
| 41 | |
| 42 | template <int Dummy> struct NoCompare {}; |
| 43 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 44 | int main(int, char**) |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 45 | { |
| 46 | { |
| 47 | typedef NoCompare<0> T; |
| 48 | typedef std::array<T, 3> C; |
| 49 | C c1 = {{}}; |
| 50 | // expected-error@algorithm:* 2 {{invalid operands to binary expression}} |
| 51 | TEST_IGNORE_NODISCARD (c1 == c1); |
| 52 | TEST_IGNORE_NODISCARD (c1 < c1); |
| 53 | } |
| 54 | { |
| 55 | typedef NoCompare<1> T; |
| 56 | typedef std::array<T, 3> C; |
| 57 | C c1 = {{}}; |
| 58 | // expected-error@algorithm:* 2 {{invalid operands to binary expression}} |
| 59 | TEST_IGNORE_NODISCARD (c1 != c1); |
| 60 | TEST_IGNORE_NODISCARD (c1 > c1); |
| 61 | } |
| 62 | { |
| 63 | typedef NoCompare<2> T; |
| 64 | typedef std::array<T, 0> C; |
| 65 | C c1 = {{}}; |
| 66 | // expected-error@algorithm:* 2 {{invalid operands to binary expression}} |
| 67 | TEST_IGNORE_NODISCARD (c1 == c1); |
| 68 | TEST_IGNORE_NODISCARD (c1 < c1); |
| 69 | } |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 70 | |
| 71 | return 0; |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 72 | } |