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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10
11 // In MSVC mode, there's a slightly different number of errors printed for
12 // each of these, so it doesn't add up to the exact expected count of 18.
13 // XFAIL: msvc
14
15 // <compare>
16
17 // Ensure we reject all cases where an argument other than a literal 0 is used
18 // for a comparison against a comparison category type.
19
20 #include <compare>
21
22 #define TEST_FAIL(v, op) \
23 void(v op 0L); \
24 void(0L op v); \
25 void(v op nullptr); \
26 void(nullptr op v); \
27 void(v op(1 - 1)); \
28 void((1 - 1) op v)
29
30 #define TEST_PASS(v, op) \
31 void(v op 0); \
32 void(0 op v)
33
34 template <typename T>
test_category(T v)35 void test_category(T v) {
36 TEST_FAIL(v, ==); // expected-error 18 {{}}
37 TEST_FAIL(v, !=); // expected-error 18 {{}}
38 TEST_FAIL(v, <); // expected-error 18 {{}}
39 TEST_FAIL(v, <=); // expected-error 18 {{}}
40 TEST_FAIL(v, >); // expected-error 18 {{}}
41 TEST_FAIL(v, >=); // expected-error 18 {{}}
42 TEST_FAIL(v, <=>); // expected-error 18 {{}}
43
44 TEST_PASS(v, ==);
45 TEST_PASS(v, !=);
46 TEST_PASS(v, <);
47 TEST_PASS(v, >);
48 TEST_PASS(v, <=);
49 TEST_PASS(v, >=);
50 TEST_PASS(v, <=>);
51 }
52
f()53 void f() {
54 test_category(std::strong_ordering::equivalent);
55 test_category(std::weak_ordering::equivalent);
56 test_category(std::partial_ordering::equivalent);
57 }
58