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 // GCC 5 does not evaluate static assertions dependent on a template parameter.
10 // UNSUPPORTED: gcc-5
11
12 // <array>
13
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 // bool operator<=(array<T, N> const&, array<T, N> const&);
18 // bool operator>(array<T, N> const&, array<T, N> const&);
19 // bool operator>=(array<T, N> const&, array<T, N> const&);
20
21
22 #include <array>
23 #include <vector>
24 #include <cassert>
25
26 #include "test_macros.h"
27
28 // std::array is explicitly allowed to be initialized with A a = { init-list };.
29 // Disable the missing braces warning for this reason.
30 #include "disable_missing_braces_warning.h"
31
32 template <class Array>
test_compare(const Array & LHS,const Array & RHS)33 void test_compare(const Array& LHS, const Array& RHS) {
34 typedef std::vector<typename Array::value_type> Vector;
35 const Vector LHSV(LHS.begin(), LHS.end());
36 const Vector RHSV(RHS.begin(), RHS.end());
37 assert((LHS == RHS) == (LHSV == RHSV));
38 assert((LHS != RHS) == (LHSV != RHSV));
39 assert((LHS < RHS) == (LHSV < RHSV));
40 assert((LHS <= RHS) == (LHSV <= RHSV));
41 assert((LHS > RHS) == (LHSV > RHSV));
42 assert((LHS >= RHS) == (LHSV >= RHSV));
43 }
44
45 template <int Dummy> struct NoCompare {};
46
main(int,char **)47 int main(int, char**)
48 {
49 {
50 typedef NoCompare<0> T;
51 typedef std::array<T, 3> C;
52 C c1 = {{}};
53 // expected-error@algorithm:* 2 {{invalid operands to binary expression}}
54 TEST_IGNORE_NODISCARD (c1 == c1);
55 TEST_IGNORE_NODISCARD (c1 < c1);
56 }
57 {
58 typedef NoCompare<1> T;
59 typedef std::array<T, 3> C;
60 C c1 = {{}};
61 // expected-error@algorithm:* 2 {{invalid operands to binary expression}}
62 TEST_IGNORE_NODISCARD (c1 != c1);
63 TEST_IGNORE_NODISCARD (c1 > c1);
64 }
65 {
66 typedef NoCompare<2> T;
67 typedef std::array<T, 0> C;
68 C c1 = {{}};
69 // expected-error@algorithm:* 2 {{invalid operands to binary expression}}
70 TEST_IGNORE_NODISCARD (c1 == c1);
71 TEST_IGNORE_NODISCARD (c1 < c1);
72 }
73
74 return 0;
75 }
76