The attribute is now allowed on an assortment of declarations, to suppress warnings related to declarations themselves, or all warnings in the lexical scope of the declaration. I don't necessarily see a reason to have a list at all, but it does look as if some of those more niche items aren't properly supported by the compiler itself so let's maintain a short safe list for now. The initial implementation raised a question whether the attribute should apply to lexical declaration context vs. "actual" declaration context. I'm using "lexical" here because it results in less warnings suppressed, which is the conservative behavior: we can always expand it later if we think this is wrong, without breaking any existing code. I also think that this is the correct behavior that we will probably never want to change, given that the user typically desires to keep the suppressions as localized as possible.
50 lines
2.5 KiB
C++
50 lines
2.5 KiB
C++
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker %s 2>&1 | FileCheck %s --strict-whitespace
|
|
#include "mock-types.h"
|
|
|
|
void raw_ptr() {
|
|
RefCountable* ref_countable = nullptr;
|
|
auto foo1 = [ref_countable](){};
|
|
// CHECK: warning: Captured raw-pointer 'ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
// CHECK-NEXT:{{^ 6 | }} auto foo1 = [ref_countable](){};
|
|
// CHECK-NEXT:{{^ | }} ^
|
|
auto foo2 = [&ref_countable](){};
|
|
// CHECK: warning: Captured raw-pointer 'ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
auto foo3 = [&](){ ref_countable = nullptr; };
|
|
// CHECK: warning: Implicitly captured raw-pointer 'ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
// CHECK-NEXT:{{^ 12 | }} auto foo3 = [&](){ ref_countable = nullptr; };
|
|
// CHECK-NEXT:{{^ | }} ^
|
|
auto foo4 = [=](){ (void) ref_countable; };
|
|
// CHECK: warning: Implicitly captured raw-pointer 'ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
|
|
// Confirm that the checker respects [[clang::suppress]].
|
|
RefCountable* suppressed_ref_countable = nullptr;
|
|
[[clang::suppress]] auto foo5 = [suppressed_ref_countable](){};
|
|
// CHECK-NOT: warning: Captured raw-pointer 'suppressed_ref_countable' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
}
|
|
|
|
void references() {
|
|
RefCountable automatic;
|
|
RefCountable& ref_countable_ref = automatic;
|
|
|
|
auto foo1 = [ref_countable_ref](){};
|
|
// CHECK: warning: Captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
auto foo2 = [&ref_countable_ref](){};
|
|
// CHECK: warning: Captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
auto foo3 = [&](){ (void) ref_countable_ref; };
|
|
// CHECK: warning: Implicitly captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
auto foo4 = [=](){ (void) ref_countable_ref; };
|
|
// CHECK: warning: Implicitly captured reference 'ref_countable_ref' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]
|
|
}
|
|
|
|
void quiet() {
|
|
// This code is not expected to trigger any warnings.
|
|
{
|
|
RefCountable automatic;
|
|
RefCountable &ref_countable_ref = automatic;
|
|
}
|
|
|
|
auto foo3 = [&]() {};
|
|
auto foo4 = [=]() {};
|
|
RefCountable *ref_countable = nullptr;
|
|
}
|