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