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
parent bfd5b53352
commit aa2b0131c4
2 changed files with 27 additions and 3 deletions

View File

@ -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)) {

View File

@ -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);
});
}