Bug 1242789 - Allow lambdas to capture raw pointers to refcounted objects by reference, r=ehsan

This commit is contained in:
Michael Layzell 2016-01-25 19:54:05 -05:00
Родитель 41666e40fd
Коммит 299ac653c2
2 изменённых файлов: 27 добавлений и 3 удалений

Просмотреть файл

@ -1272,7 +1272,7 @@ void DiagnosticsMatcher::RefCountedInsideLambdaChecker::run(
const LambdaExpr *Lambda = Result.Nodes.getNodeAs<LambdaExpr>("lambda");
for (const LambdaCapture Capture : Lambda->captures()) {
if (Capture.capturesVariable()) {
if (Capture.capturesVariable() && Capture.getCaptureKind() != LCK_ByRef) {
QualType Pointee = Capture.getCapturedVar()->getType()->getPointeeType();
if (!Pointee.isNull() && isClassRefCounted(Pointee)) {

Просмотреть файл

@ -21,7 +21,7 @@ void foo() {
SmartPtr<R> sp;
take([&](R* argptr) {
R* localptr;
ptr->method(); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be captured by a lambda}} expected-note{{Please consider using a smart pointer}}
ptr->method();
argptr->method();
localptr->method();
});
@ -33,7 +33,7 @@ void foo() {
});
take([&](R* argptr) {
R* localptr;
take(ptr); // expected-error{{Refcounted variable 'ptr' of type 'R' cannot be captured by a lambda}} expected-note{{Please consider using a smart pointer}}
take(ptr);
take(argptr);
take(localptr);
});
@ -91,4 +91,28 @@ void foo() {
take(argsp);
take(localsp);
});
take([&ptr](R* argptr) {
R* localptr;
ptr->method();
argptr->method();
localptr->method();
});
take([&sp](SmartPtr<R> argsp) {
SmartPtr<R> localsp;
sp->method();
argsp->method();
localsp->method();
});
take([&ptr](R* argptr) {
R* localptr;
take(ptr);
take(argptr);
take(localptr);
});
take([&sp](SmartPtr<R> argsp) {
SmartPtr<R> localsp;
take(sp);
take(argsp);
take(localsp);
});
}