1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify -std=c++2a %s
4 static const unsigned long long scull
= 0;
7 *(int*)scull
= 0; // expected-warning{{Dereference of null pointer}}
10 const unsigned long long cull
= 0;
13 *(int*)cull
= 0; // expected-warning{{Dereference of null pointer}}
16 static int * const spc
= 0;
19 *spc
= 0; // expected-warning{{Dereference of null pointer}}
25 *pc
= 0; // expected-warning{{Dereference of null pointer}}
28 const unsigned long long cull_nonnull
= 4;
31 *(int*)(cull_nonnull
- 4) = 0; // expected-warning{{Dereference of null pointer}}
34 int * const pc_nonnull
= (int*)sizeof(int);
37 *(pc_nonnull
- 1) = 0; // expected-warning{{Dereference of null pointer}}
40 int * const constcast
= const_cast<int * const>((int*)sizeof(int));
43 *(constcast
- 1) = 0; // expected-warning{{Dereference of null pointer}}
46 int * const recast
= reinterpret_cast<int*>(sizeof(int));
49 *(recast
- 1) = 0; // expected-warning{{Dereference of null pointer}}
52 int * const staticcast
= static_cast<int * const>((int*)sizeof(int));
55 *(staticcast
- 1) = 0; // expected-warning{{Dereference of null pointer}}
58 struct Foo
{ int a
; };
59 Foo
* const dyncast
= dynamic_cast<Foo
* const>((Foo
*)sizeof(Foo
));
62 // Do not handle dynamic_cast for now, because it may change the pointer value.
63 (dyncast
- 1)->a
= 0; // no-warning
66 typedef int * const intptrconst
;
67 int * const funccast
= intptrconst(sizeof(int));
70 *(funccast
- 1) = 0; // expected-warning{{Dereference of null pointer}}
78 .p
= (int*)sizeof(int)
82 *(s1
.p
- 1) = 0; // expected-warning{{Dereference of null pointer}}
90 .p
= (int*)sizeof(int)
94 *(s2
.p
- 1) = 0; // expected-warning{{Dereference of null pointer}}
97 int * const parr
[1] = { (int*)sizeof(int) };
100 *(parr
[0] - 1) = 0; // expected-warning{{Dereference of null pointer}}
105 int * p
= (int*)sizeof(int);
110 *(s3
.p
- 1) = 0; // expected-warning{{Dereference of null pointer}}
115 void update_original_declaration() {
121 int test_redeclaration() {
123 update_original_declaration();
124 int int_int
= 3 / (ext_int
- 1); // no-warning
125 return int_int
/ (ext_int
- 2); // expected-warning{{Division by zero}}