|
26 | 26 |
|
27 | 27 | #include "test_macros.h" |
28 | 28 |
|
29 | | -#define TEST_FAIL_INVALID_VALUE(v, op) \ |
30 | | - do { \ |
31 | | - void(v op 1); \ |
32 | | - void(1 op v); \ |
33 | | - } while (false) |
34 | | - |
35 | | -#define TEST_FAIL_INVALID_TYPE(v, op) \ |
| 29 | +#define TEST_FAIL(v, op) \ |
36 | 30 | do { \ |
| 31 | + /* invalid types */ \ |
37 | 32 | void(v op 0L); \ |
38 | 33 | void(0L op v); \ |
39 | 34 | void(v op 0.0); \ |
40 | 35 | void(0.0 op v); \ |
41 | 36 | void(v op nullptr); \ |
42 | 37 | void(nullptr op v); \ |
43 | | - } while (false) |
44 | | - |
45 | | -#define TEST_FAIL_NOT_COMPILE_TIME(v, op) \ |
46 | | - do { \ |
| 38 | + /* invalid value */ \ |
| 39 | + void(v op 1); \ |
| 40 | + void(1 op v); \ |
| 41 | + /* value not known at compile-time */ \ |
47 | 42 | int i = 0; \ |
48 | 43 | void(v op i); \ |
49 | 44 | void(i op v); \ |
|
59 | 54 |
|
60 | 55 | template <typename T> |
61 | 56 | void test_category(T v) { |
62 | | - TEST_FAIL_INVALID_TYPE(v, ==); // expected-error 18 {{invalid operands to binary expression}} |
63 | | - TEST_FAIL_INVALID_TYPE(v, !=); // expected-error 18 {{invalid operands to binary expression}} |
64 | | - TEST_FAIL_INVALID_TYPE(v, <); // expected-error 18 {{invalid operands to binary expression}} |
65 | | - TEST_FAIL_INVALID_TYPE(v, <=); // expected-error 18 {{invalid operands to binary expression}} |
66 | | - TEST_FAIL_INVALID_TYPE(v, >); // expected-error 18 {{invalid operands to binary expression}} |
67 | | - TEST_FAIL_INVALID_TYPE(v, >=); // expected-error 18 {{invalid operands to binary expression}} |
68 | | - TEST_FAIL_INVALID_TYPE(v, <=>); // expected-error 18 {{invalid operands to binary expression}} |
69 | | - |
70 | | - TEST_FAIL_INVALID_VALUE(v, ==); // expected-error 6 {{Only literal 0 is allowed as the operand}} |
71 | | - TEST_FAIL_INVALID_VALUE(v, !=); // expected-error 6 {{Only literal 0 is allowed as the operand}} |
72 | | - TEST_FAIL_INVALID_VALUE(v, <); // expected-error 6 {{Only literal 0 is allowed as the operand}} |
73 | | - TEST_FAIL_INVALID_VALUE(v, <=); // expected-error 6 {{Only literal 0 is allowed as the operand}} |
74 | | - TEST_FAIL_INVALID_VALUE(v, >); // expected-error 6 {{Only literal 0 is allowed as the operand}} |
75 | | - TEST_FAIL_INVALID_VALUE(v, >=); // expected-error 6 {{Only literal 0 is allowed as the operand}} |
76 | | - TEST_FAIL_INVALID_VALUE(v, <=>); // expected-error 6 {{Only literal 0 is allowed as the operand}} |
77 | | - |
78 | | - TEST_FAIL_NOT_COMPILE_TIME(v, ==); // expected-error 6 {{call to consteval function}} |
79 | | - TEST_FAIL_NOT_COMPILE_TIME(v, !=); // expected-error 6 {{call to consteval function}} |
80 | | - TEST_FAIL_NOT_COMPILE_TIME(v, <); // expected-error 6 {{call to consteval function}} |
81 | | - TEST_FAIL_NOT_COMPILE_TIME(v, <=); // expected-error 6 {{call to consteval function}} |
82 | | - TEST_FAIL_NOT_COMPILE_TIME(v, >); // expected-error 6 {{call to consteval function}} |
83 | | - TEST_FAIL_NOT_COMPILE_TIME(v, >=); // expected-error 6 {{call to consteval function}} |
84 | | - TEST_FAIL_NOT_COMPILE_TIME(v, <=>); // expected-error 6 {{call to consteval function}} |
| 57 | + TEST_FAIL(v, ==); // expected-error 30 {{invalid operands to binary expression}} |
| 58 | + TEST_FAIL(v, !=); // expected-error 30 {{invalid operands to binary expression}} |
| 59 | + TEST_FAIL(v, <); // expected-error 30 {{invalid operands to binary expression}} |
| 60 | + TEST_FAIL(v, <=); // expected-error 30 {{invalid operands to binary expression}} |
| 61 | + TEST_FAIL(v, >); // expected-error 30 {{invalid operands to binary expression}} |
| 62 | + TEST_FAIL(v, >=); // expected-error 30 {{invalid operands to binary expression}} |
| 63 | + TEST_FAIL(v, <=>); // expected-error 30 {{invalid operands to binary expression}} |
85 | 64 |
|
86 | 65 | TEST_PASS(v, ==); |
87 | 66 | TEST_PASS(v, !=); |
|
0 commit comments