Skip to content

Commit edc0413

Browse files
committed
handle refs
1 parent 546567e commit edc0413

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang-tools-extra/clang-tidy/bugprone/TaxiAsyncUseAfterFreeCheck.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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");

clang-tools-extra/test/clang-tidy/checkers/bugprone/taxi-async-use-after-free.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,26 @@ void f_ok() {
2828

2929
void 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+
}

0 commit comments

Comments
 (0)