Debian Codegraph @

clang/test/Analysis/suppression-attr.cpp

raw
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
2
3 namespace [[clang::suppress]]
4 suppressed_namespace {
5 int foo() {
6 int *x = 0;
7 return *x;
8 }
9
10 int foo_forward();
11 }
12
13 int suppressed_namespace::foo_forward() {
14 int *x = 0;
15 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
16 }
17
18 // Another instance of the same namespace.
19 namespace suppressed_namespace {
20 int bar() {
21 int *x = 0;
22 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
23 }
24 }
25
26 void lambda() {
27 [[clang::suppress]] {
28 auto lam = []() {
29 int *x = 0;
30 return *x;
31 };
32 }
33 }
34
35 class [[clang::suppress]] SuppressedClass {
36 int foo() {
37 int *x = 0;
38 return *x;
39 }
40
41 int bar();
42 };
43
44 int SuppressedClass::bar() {
45 int *x = 0;
46 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
47 }
48
49 class SuppressedMethodClass {
50 [[clang::suppress]] int foo() {
51 int *x = 0;
52 return *x;
53 }
54
55 [[clang::suppress]] int bar1();
56 int bar2();
57 };
58
59 int SuppressedMethodClass::bar1() {
60 int *x = 0;
61 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
62 }
63
64 [[clang::suppress]]
65 int SuppressedMethodClass::bar2() {
66 int *x = 0;
67 return *x; // no-warning
68 }