nullptr_in_arithmetic_ops.cpp
4.36 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-pointer-compare -fblocks -std=c++11 -verify %s
void foo() {
int a;
bool b;
a = 0 ? nullptr + a : a + nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr - a : a - nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr / a : a / nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr * a : a * nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr >> a : a >> nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr << a : a << nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr % a : a % nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr & a : a & nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr | a : a | nullptr; // expected-error 2{{invalid operands to binary expression}}
a = 0 ? nullptr ^ a : a ^ nullptr; // expected-error 2{{invalid operands to binary expression}}
// Using two nullptrs should only give one error instead of two.
a = nullptr + nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr - nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr / nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr * nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr >> nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr << nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr % nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr & nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr | nullptr; // expected-error{{invalid operands to binary expression}}
a = nullptr ^ nullptr; // expected-error{{invalid operands to binary expression}}
a += nullptr; // expected-error{{invalid operands to binary expression}}
a -= nullptr; // expected-error{{invalid operands to binary expression}}
a /= nullptr; // expected-error{{invalid operands to binary expression}}
a *= nullptr; // expected-error{{invalid operands to binary expression}}
a >>= nullptr; // expected-error{{invalid operands to binary expression}}
a <<= nullptr; // expected-error{{invalid operands to binary expression}}
a %= nullptr; // expected-error{{invalid operands to binary expression}}
a &= nullptr; // expected-error{{invalid operands to binary expression}}
a |= nullptr; // expected-error{{invalid operands to binary expression}}
a ^= nullptr; // expected-error{{invalid operands to binary expression}}
b = a < nullptr || nullptr < a; // expected-error 2{{invalid operands to binary expression}}
b = a > nullptr || nullptr > a; // expected-error 2{{invalid operands to binary expression}}
b = a <= nullptr || nullptr <= a; // expected-error 2{{invalid operands to binary expression}}
b = a >= nullptr || nullptr >= a; // expected-error 2{{invalid operands to binary expression}}
b = a == nullptr || nullptr == a; // expected-error 2{{invalid operands to binary expression}}
b = a != nullptr || nullptr != a; // expected-error 2{{invalid operands to binary expression}}
b = &a < nullptr || nullptr < &a || &a > nullptr || nullptr > &a; // expected-error 4{{invalid operands}}
b = &a <= nullptr || nullptr <= &a || &a >= nullptr || nullptr >= &a; // expected-error 4{{invalid operands}}
b = &a == nullptr || nullptr == &a || &a != nullptr || nullptr != &a;
b = nullptr < nullptr || nullptr > nullptr; // expected-error 2{{invalid operands to binary expression}}
b = nullptr <= nullptr || nullptr >= nullptr; // expected-error 2{{invalid operands to binary expression}}
b = nullptr == nullptr || nullptr != nullptr;
b = ((nullptr)) != a; // expected-error{{invalid operands to binary expression}}
void (^c)();
c = nullptr;
b = c == nullptr || nullptr == c || c != nullptr || nullptr != c;
class X;
void (X::*d) ();
d = nullptr;
b = d == nullptr || nullptr == d || d != nullptr || nullptr != d;
extern void e();
b = e == nullptr || nullptr == e || e != nullptr || nullptr != e;
int f[2];
b = f == nullptr || nullptr == f || f != nullptr || nullptr != f;
b = "f" == nullptr || nullptr == "f" || "f" != nullptr || nullptr != "f";
}