1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++03, c++11, c++14, c++17
11
12 // <compare>
13
14 // Ensure we reject all cases where an argument other than a literal 0 is used
15 // for a comparison against a comparison category type.
16
17 #include <compare>
18
19 #define TEST_OP(v, op) \
20 void(v op 0L); \
21 void(0L op v); \
22 void(v op nullptr); \
23 void(nullptr op v); \
24 void(v op(1 - 1)); \
25 void((1 - 1) op v);
26
27 template <typename T>
test_category(T v)28 void test_category(T v) {
29 TEST_OP(v, ==); // expected-error 18 {{}}
30 TEST_OP(v, !=); // expected-error 18 {{}}
31 TEST_OP(v, <); // expected-error 18 {{}}
32 TEST_OP(v, <=); // expected-error 18 {{}}
33 TEST_OP(v, >); // expected-error 18 {{}}
34 TEST_OP(v, >=); // expected-error 18 {{}}
35 TEST_OP(v, <=>); // expected-error 18 {{}}
36
37 void(v == 0);
38 void(0 == v);
39 void(v != 0);
40 void(0 != v);
41 void(v < 0);
42 void(0 < v);
43 void(v <= 0);
44 void(0 <= v);
45 void(v > 0);
46 void(0 > v);
47 void(v >= 0);
48 void(0 >= v);
49 #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
50 void(v <=> 0);
51 void(0 <=> v);
52 #endif
53 }
54
main(int,char **)55 int main(int, char**) {
56 test_category(std::strong_ordering::equivalent);
57 test_category(std::weak_ordering::equivalent);
58 test_category(std::partial_ordering::equivalent);
59 return 0;
60 }
61