Files
clang-p2996/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp
Ryosuke Niwa 5c3b05996f [alpha.webkit.UnretainedLambdaCapturesChecker] Add a WebKit checker for lambda capturing NS or CF types. (#128651)
Add a new WebKit checker for checking that lambda captures of CF types
use RetainPtr either when ARC is disabled or enabled, and those of NS
types use RetainPtr when ARC is disabled.
2025-03-09 14:59:46 -07:00

39 lines
944 B
C++

// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s
struct Foo {
int x;
int y;
Foo(int x, int y) : x(x) , y(y) { }
};
template <typename T>
struct Baz {
void ref() const;
void deref() const;
Foo operator*();
bool operator!();
};
inline Foo operator*(const Foo& a, const Foo& b);
Baz<Foo> someFunction();
template <typename CallbackType> void bar(CallbackType callback) {
auto baz = someFunction();
callback(baz);
}
struct Obj {
void ref() const;
void deref() const;
void foo(Foo foo) {
bar([this](auto baz) {
// expected-warning@-1{{Captured raw-pointer 'this' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]}}
bar([this, foo = *baz, foo2 = !baz](auto&&) {
// expected-warning@-1{{Captured raw-pointer 'this' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]}}
someFunction();
});
});
}
};