compare.fail.cpp 2.2 KB

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