File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ void TaxiAsyncUseAfterFreeCheck::check(const MatchFinder::MatchResult& Result) {
4242 continue ;
4343
4444 const ValueDecl* CapturedVarDecl = Capture.getCapturedVar ();
45+ if (CapturedVarDecl->getType ().getCanonicalType ()->isLValueReferenceType () ||
46+ CapturedVarDecl->getType ().getCanonicalType ()->isRValueReferenceType ()) {
47+ continue ;
48+ }
49+
4550 if (CapturedVarDecl->getLocation () >= TasksLocation) {
4651 diag (Capture.getLocation (), " captured here" );
4752 diag (CapturedVarDecl->getLocation (), " variable can be used after free" );
Original file line number Diff line number Diff line change @@ -28,8 +28,26 @@ void f_ok() {
2828
2929void f_use_after_free () {
3030 std::vector<int > v;
31+ // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: std::vector<Task> can die after variable [bugprone-taxi-async-use-after-free]
3132 int x = 1 ;
33+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable can be used after free [bugprone-taxi-async-use-after-free]
3234
3335 v.push_back (engine::Async ([&x]{ x = 2 ;}));
36+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: captured here [bugprone-taxi-async-use-after-free]
3437}
3538
39+ void f_ref () {
40+ int xx = 1 ;
41+ std::vector<int > v;
42+ int &x = x;
43+
44+ v.push_back (engine::Async ([&x]{ x = 2 ;}));
45+ }
46+
47+ void f_ref_ref () {
48+ int xx = 1 ;
49+ std::vector<int > v;
50+ int &&x = static_cast <int &&>(xx);
51+
52+ v.push_back (engine::Async ([&x]{ x = 2 ;}));
53+ }
You can’t perform that action at this time.
0 commit comments