blob: 47859ad49db525070819fd1c3b4d5e3edac8c385 [file] [log] [blame]
Eric Fiselier59cdf902018-02-07 21:06:13 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Fiselier59cdf902018-02-07 21:06:13 +00006//
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
29template <class Array>
30void 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
42template <int Dummy> struct NoCompare {};
43
JF Bastien2df59c52019-02-04 20:31:13 +000044int main(int, char**)
Eric Fiselier59cdf902018-02-07 21:06:13 +000045{
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 Bastien2df59c52019-02-04 20:31:13 +000070
71 return 0;
Eric Fiselier59cdf902018-02-07 21:06:13 +000072}