[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / nullptr_in_arithmetic_ops.cpp
blob98bec184164b63b012e933d01439640ec69f8712
1 // RUN: %clang_cc1 -fsyntax-only -Wno-tautological-pointer-compare -fblocks -std=c++11 -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -Wno-tautological-pointer-compare -fblocks -std=c++11 -verify %s -fexperimental-new-constant-interpreter
4 void foo() {
5 int a;
6 bool b;
8 a = 0 ? nullptr + a : a + nullptr; // expected-error 2{{invalid operands to binary expression}}
9 a = 0 ? nullptr - a : a - nullptr; // expected-error 2{{invalid operands to binary expression}}
10 a = 0 ? nullptr / a : a / nullptr; // expected-error 2{{invalid operands to binary expression}}
11 a = 0 ? nullptr * a : a * nullptr; // expected-error 2{{invalid operands to binary expression}}
12 a = 0 ? nullptr >> a : a >> nullptr; // expected-error 2{{invalid operands to binary expression}}
13 a = 0 ? nullptr << a : a << nullptr; // expected-error 2{{invalid operands to binary expression}}
14 a = 0 ? nullptr % a : a % nullptr; // expected-error 2{{invalid operands to binary expression}}
15 a = 0 ? nullptr & a : a & nullptr; // expected-error 2{{invalid operands to binary expression}}
16 a = 0 ? nullptr | a : a | nullptr; // expected-error 2{{invalid operands to binary expression}}
17 a = 0 ? nullptr ^ a : a ^ nullptr; // expected-error 2{{invalid operands to binary expression}}
19 // Using two nullptrs should only give one error instead of two.
20 a = nullptr + nullptr; // expected-error{{invalid operands to binary expression}}
21 a = nullptr - nullptr; // expected-error{{invalid operands to binary expression}}
22 a = nullptr / nullptr; // expected-error{{invalid operands to binary expression}}
23 a = nullptr * nullptr; // expected-error{{invalid operands to binary expression}}
24 a = nullptr >> nullptr; // expected-error{{invalid operands to binary expression}}
25 a = nullptr << nullptr; // expected-error{{invalid operands to binary expression}}
26 a = nullptr % nullptr; // expected-error{{invalid operands to binary expression}}
27 a = nullptr & nullptr; // expected-error{{invalid operands to binary expression}}
28 a = nullptr | nullptr; // expected-error{{invalid operands to binary expression}}
29 a = nullptr ^ nullptr; // expected-error{{invalid operands to binary expression}}
31 a += nullptr; // expected-error{{invalid operands to binary expression}}
32 a -= nullptr; // expected-error{{invalid operands to binary expression}}
33 a /= nullptr; // expected-error{{invalid operands to binary expression}}
34 a *= nullptr; // expected-error{{invalid operands to binary expression}}
35 a >>= nullptr; // expected-error{{invalid operands to binary expression}}
36 a <<= nullptr; // expected-error{{invalid operands to binary expression}}
37 a %= nullptr; // expected-error{{invalid operands to binary expression}}
38 a &= nullptr; // expected-error{{invalid operands to binary expression}}
39 a |= nullptr; // expected-error{{invalid operands to binary expression}}
40 a ^= nullptr; // expected-error{{invalid operands to binary expression}}
42 b = a < nullptr || nullptr < a; // expected-error 2{{invalid operands to binary expression}}
43 b = a > nullptr || nullptr > a; // expected-error 2{{invalid operands to binary expression}}
44 b = a <= nullptr || nullptr <= a; // expected-error 2{{invalid operands to binary expression}}
45 b = a >= nullptr || nullptr >= a; // expected-error 2{{invalid operands to binary expression}}
46 b = a == nullptr || nullptr == a; // expected-error 2{{invalid operands to binary expression}}
47 b = a != nullptr || nullptr != a; // expected-error 2{{invalid operands to binary expression}}
49 b = &a < nullptr || nullptr < &a || &a > nullptr || nullptr > &a; // expected-error 4{{invalid operands}}
50 b = &a <= nullptr || nullptr <= &a || &a >= nullptr || nullptr >= &a; // expected-error 4{{invalid operands}}
51 b = &a == nullptr || nullptr == &a || &a != nullptr || nullptr != &a;
53 b = nullptr < nullptr || nullptr > nullptr; // expected-error 2{{invalid operands to binary expression}}
54 b = nullptr <= nullptr || nullptr >= nullptr; // expected-error 2{{invalid operands to binary expression}}
55 b = nullptr == nullptr || nullptr != nullptr;
57 b = ((nullptr)) != a; // expected-error{{invalid operands to binary expression}}
59 void (^c)();
60 c = nullptr;
61 b = c == nullptr || nullptr == c || c != nullptr || nullptr != c;
63 class X;
64 void (X::*d) ();
65 d = nullptr;
66 b = d == nullptr || nullptr == d || d != nullptr || nullptr != d;
68 extern void e();
69 b = e == nullptr || nullptr == e || e != nullptr || nullptr != e;
71 int f[2];
72 b = f == nullptr || nullptr == f || f != nullptr || nullptr != f;
73 b = "f" == nullptr || nullptr == "f" || "f" != nullptr || nullptr != "f";