39 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s2 3struct Foo {4 int x;5 int y;6 Foo(int x, int y) : x(x) , y(y) { }7};8 9template <typename T>10struct Baz {11 void ref() const;12 void deref() const;13 Foo operator*();14 bool operator!();15};16 17inline Foo operator*(const Foo& a, const Foo& b);18 19Baz<Foo> someFunction();20template <typename CallbackType> void bar(CallbackType callback) {21 auto baz = someFunction();22 callback(baz);23}24 25struct 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};39