Don't warn about unused lambda captures that involve copying a
value of a type that cannot be trivially copied and destroyed.
Fixes PR31977
Paths
| Differential D30327
[Sema] Improve side effect checking for unused-lambda-capture warning ClosedPublic Authored by malcolm.parsons on Feb 24 2017, 1:56 AM.
Details Summary Don't warn about unused lambda captures that involve copying a Fixes PR31977
Diff Detail
Event Timeline
Comment Actions I found this FIXME comment in Expr::HasSideEffects(): case LambdaExprClass: { const LambdaExpr *LE = cast<LambdaExpr>(this); for (LambdaExpr::capture_iterator I = LE->capture_begin(), E = LE->capture_end(); I != E; ++I) if (I->getCaptureKind() == LCK_ByCopy) // FIXME: Only has a side-effect if the variable is volatile or if // the copy would invoke a non-trivial copy constructor. return true; return false; } It seems a shame not to fix this now, but I don't think I can call Sema code from AST code, and my CaptureHasSideEffects() depends on Sema::getCurrentThisType(). Any ideas? malcolm.parsons marked an inline comment as done. Comment ActionsHandle captures of volatile variables. Comment Actions LGTM!
Correct, you cannot call Sema code from AST. I don't know of a good way to resolve this off the top of my head given what getCurrentThisType() needs to do. I agree that this would be good to fix as well, but your patch is a good incremental improvement and should't be held up on this. This revision is now accepted and ready to land.Feb 28 2017, 1:06 PM Closed by commit rL296602: [Sema] Improve side effect checking for unused-lambda-capture warning (authored by malcolm.parsons). · Explain WhyMar 1 2017, 2:35 AM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 90139 cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
|