1// REQUIRES: static-analyzer
2// RUN: clang-tidy -checks='-*,clang-analyzer-core.NullDereference' %s -- | FileCheck %s
3
4struct NoReturnDtor {
5 ~NoReturnDtor() __attribute__((noreturn));
6};
7
8extern bool check(const NoReturnDtor &);
9
10// CHECK-NOT: warning
11void 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
18void 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

source code of clang-tools-extra/test/clang-tidy/infrastructure/temporaries.cpp