1 // RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker %s 2>&1 | FileCheck %s --strict-whitespace 2 #include "mock-types.h" 3 raw_ptr()4void 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:{{^}} 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:{{^}} 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 references()20void references() { 21 RefCountable automatic; 22 RefCountable& ref_countable_ref = automatic; 23 24 auto foo1 = [ref_countable_ref](){}; 25 // CHECK: warning: Captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker] 26 auto foo2 = [&ref_countable_ref](){}; 27 // CHECK: warning: Captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker] 28 auto foo3 = [&](){ (void) ref_countable_ref; }; 29 // CHECK: warning: Implicitly captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker] 30 auto foo4 = [=](){ (void) ref_countable_ref; }; 31 // CHECK: warning: Implicitly captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker] 32 } 33 quiet()34void quiet() { 35 // This code is not expected to trigger any warnings. 36 { 37 RefCountable automatic; 38 RefCountable &ref_countable_ref = automatic; 39 } 40 41 auto foo3 = [&]() {}; 42 auto foo4 = [=]() {}; 43 RefCountable *ref_countable = nullptr; 44 } 45