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 //===----------------------------------------------------------------------===//
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 template <class Array>
test_compare(const Array & LHS,const Array & RHS)26 void test_compare(const Array& LHS, const Array& RHS) {
27   typedef std::vector<typename Array::value_type> Vector;
28   const Vector LHSV(LHS.begin(), LHS.end());
29   const Vector RHSV(RHS.begin(), RHS.end());
30   assert((LHS == RHS) == (LHSV == RHSV));
31   assert((LHS != RHS) == (LHSV != RHSV));
32   assert((LHS < RHS) == (LHSV < RHSV));
33   assert((LHS <= RHS) == (LHSV <= RHSV));
34   assert((LHS > RHS) == (LHSV > RHSV));
35   assert((LHS >= RHS) == (LHSV >= RHSV));
36 }
37 
38 template <int Dummy> struct NoCompare {};
39 
main(int,char **)40 int main(int, char**)
41 {
42   {
43     typedef NoCompare<0> T;
44     typedef std::array<T, 3> C;
45     C c1 = {{}};
46     // expected-error@*:* 2 {{invalid operands to binary expression}}
47     TEST_IGNORE_NODISCARD (c1 == c1);
48     TEST_IGNORE_NODISCARD (c1 < c1);
49   }
50   {
51     typedef NoCompare<1> T;
52     typedef std::array<T, 3> C;
53     C c1 = {{}};
54     // expected-error@*:* 2 {{invalid operands to binary expression}}
55     TEST_IGNORE_NODISCARD (c1 != c1);
56     TEST_IGNORE_NODISCARD (c1 > c1);
57   }
58   {
59     typedef NoCompare<2> T;
60     typedef std::array<T, 0> C;
61     C c1 = {{}};
62     // expected-error@*:* 2 {{invalid operands to binary expression}}
63     TEST_IGNORE_NODISCARD (c1 == c1);
64     TEST_IGNORE_NODISCARD (c1 < c1);
65   }
66 
67   return 0;
68 }
69