You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clang-tools-extra/test/clang-tidy/checkers/bugprone/null-check-after-dereference.cpp
+13-30Lines changed: 13 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -4,57 +4,46 @@ struct S {
4
4
int a;
5
5
};
6
6
7
-
intwarning_deref(int *p) {
7
+
voidwarning_deref(int *p) {
8
8
*p = 42;
9
9
10
10
if (p) {
11
11
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: pointer value is checked even though it cannot be null at this point [bugprone-null-check-after-dereference]
12
12
// CHECK-MESSAGES: :[[@LINE-4]]:3: note: one of the locations where the pointer's value cannot be null
13
13
// FIXME: If there's a direct path, make the error message more precise, ie. remove `one of the locations`
14
14
*p += 20;
15
-
return *p;
16
-
} else {
17
-
return0;
18
15
}
19
16
}
20
17
21
-
intwarning_member(S *q) {
18
+
voidwarning_member(S *q) {
22
19
q->a = 42;
23
20
24
21
if (q) {
25
22
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: pointer value is checked even though it cannot be null at this point
26
23
// CHECK-MESSAGES: :[[@LINE-4]]:3: note: one of the locations where the pointer's value cannot be null
27
24
q->a += 20;
28
-
return q->a;
29
-
} else {
30
-
return0;
31
25
}
32
26
}
33
27
34
-
intnegative_warning(int *p) {
28
+
voidnegative_warning(int *p) {
35
29
*p = 42;
36
30
37
31
if (!p) {
38
32
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: pointer value is checked even though it cannot be null at this point
39
33
// CHECK-MESSAGES: :[[@LINE-4]]:3: note: one of the locations where the pointer's value cannot be null
40
-
return0;
41
-
} else {
42
-
*p += 20;
43
-
return *p;
34
+
return;
44
35
}
36
+
37
+
*p += 20;
45
38
}
46
39
47
-
intno_warning(int *p, bool b) {
40
+
voidno_warning(int *p, bool b) {
48
41
if (b) {
49
42
*p = 42;
50
43
}
51
44
52
45
if (p) {
53
-
// CHECK-MESSAGES-NOT: :[[@LINE-1]]:7: warning: pointer value is checked even though it cannot be null at this point
54
46
*p += 20;
55
-
return *p;
56
-
} else {
57
-
return0;
58
47
}
59
48
}
60
49
@@ -195,18 +184,6 @@ int chained_references(int *a, int *b, int *c, int *d, int *e) {
195
184
}
196
185
197
186
if (c) {
198
-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: pointer value is checked even though it cannot be null at this point
199
-
// CHECK-MESSAGES: :[[@LINE-5]]:5: note: one of the locations where the pointer's value cannot be null
200
-
*d = 42;
201
-
}
202
-
203
-
if (d) {
204
-
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: pointer value is checked even though it cannot be null at this point
205
-
// CHECK-MESSAGES: :[[@LINE-5]]:5: note: one of the locations where the pointer's value cannot be null
206
-
*e = 42;
207
-
}
208
-
209
-
if (e) {
210
187
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: pointer value is checked even though it cannot be null at this point
211
188
// CHECK-MESSAGES: :[[@LINE-5]]:5: note: one of the locations where the pointer's value cannot be null
212
189
return *a;
@@ -282,6 +259,12 @@ int cxx17_crash(int *p) {
282
259
return0;
283
260
}
284
261
262
+
// In an earlier version, the check would crash when encountering anonymous lambdas.
263
+
voidlambda_crash(int *p) {
264
+
auto f = [p](){ *p = 42; };
265
+
f();
266
+
}
267
+
285
268
intnote_tags() {
286
269
// FIXME: Note tags are not appended to declarations
0 commit comments