Debian Codegraph @

clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp

raw
1 // RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker %s 2>&1 | FileCheck %s --strict-whitespace
2 #include "mock-types.h"
3
4 void raw_ptr() {
5 RefCountable* ref_countable = nullptr;
6 auto foo1 = [ref_countable](){};
7 // CHECK: warning: Captured raw-pointer 'ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
8 // CHECK-NEXT:{{^ 6 | }} auto foo1 = [ref_countable](){};
9 // CHECK-NEXT:{{^ | }} ^
10 auto foo2 = [&ref_countable](){};
11 // CHECK: warning: Captured raw-pointer 'ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
12 auto foo3 = [&](){ ref_countable = nullptr; };
13 // CHECK: warning: Implicitly captured raw-pointer 'ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
14 // CHECK-NEXT:{{^ 12 | }} auto foo3 = [&](){ ref_countable = nullptr; };
15 // CHECK-NEXT:{{^ | }} ^
16 auto foo4 = [=](){ (void) ref_countable; };
17 // CHECK: warning: Implicitly captured raw-pointer 'ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
18
19 // Confirm that the checker respects [[clang::suppress]].
20 RefCountable* suppressed_ref_countable = nullptr;
21 [[clang::suppress]] auto foo5 = [suppressed_ref_countable](){};
22 // CHECK-NOT: warning: Captured raw-pointer 'suppressed_ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
23 }
24
25 void references() {
26 RefCountable automatic;
27 RefCountable& ref_countable_ref = automatic;
28
29 auto foo1 = [ref_countable_ref](){};
30 // CHECK: warning: Captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
31 auto foo2 = [&ref_countable_ref](){};
32 // CHECK: warning: Captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
33 auto foo3 = [&](){ (void) ref_countable_ref; };
34 // CHECK: warning: Implicitly captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
35 auto foo4 = [=](){ (void) ref_countable_ref; };
36 // CHECK: warning: Implicitly captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
37 }
38
39 void quiet() {
40 // This code is not expected to trigger any warnings.
41 {
42 RefCountable automatic;
43 RefCountable &ref_countable_ref = automatic;
44 }
45
46 auto foo3 = [&]() {};
47 auto foo4 = [=]() {};
48 RefCountable *ref_countable = nullptr;
49 }