Debian Codegraph @

clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp

raw
1 // RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s
2
3 struct Foo {
4 int x;
5 int y;
6 Foo(int x, int y) : x(x) , y(y) { }
7 };
8
9 template <typename T>
10 struct Baz {
11 void ref() const;
12 void deref() const;
13 Foo operator*();
14 bool operator!();
15 };
16
17 inline Foo operator*(const Foo& a, const Foo& b);
18
19 Baz<Foo> someFunction();
20 template <typename CallbackType> void bar(CallbackType callback) {
21 auto baz = someFunction();
22 callback(baz);
23 }
24
25 struct Obj {
26 void ref() const;
27 void deref() const;
28
29 void foo(Foo foo) {
30 bar([this](auto baz) {
31 // expected-warning@-1{{Captured raw-pointer 'this' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]}}
32 bar([this, foo = *baz, foo2 = !baz](auto&&) {
33 // expected-warning@-1{{Captured raw-pointer 'this' to uncounted type is unsafe [webkit.UncountedLambdaCapturesChecker]}}
34 someFunction();
35 });
36 });
37 }
38 };