1 | // REQUIRES: static-analyzer |
2 | // RUN: clang-tidy -checks='-*,clang-analyzer-core.NullDereference' %s -- | FileCheck %s |
3 | |
4 | struct NoReturnDtor { |
5 | ~NoReturnDtor() __attribute__((noreturn)); |
6 | }; |
7 | |
8 | extern bool check(const NoReturnDtor &); |
9 | |
10 | // CHECK-NOT: warning |
11 | void testNullPointerDereferencePositive() { |
12 | int *value = 0; |
13 | // CHECK: [[@LINE+1]]:10: warning: Dereference of null pointer (loaded from variable 'value') [clang-analyzer-core.NullDereference] |
14 | *value = 1; |
15 | } |
16 | |
17 | // CHECK-NOT: warning |
18 | void testNullPointerDereference() { |
19 | int *value = 0; |
20 | if (check(NoReturnDtor())) { |
21 | // This unreachable code causes a warning if analysis of temporary |
22 | // destructors is not enabled. |
23 | *value = 1; |
24 | } |
25 | } |
26 | |