File tree 3 files changed +38
-2
lines changed
3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -379,6 +379,8 @@ Improvements to Clang's diagnostics
379
379
380
380
Fixes #GH131127
381
381
382
+ - The ``-Wloop-analysis `` warning now handles variable modifications inside lambda expressions (#GH132038).
383
+
382
384
Improvements to Clang's time-trace
383
385
----------------------------------
384
386
Original file line number Diff line number Diff line change @@ -2002,9 +2002,28 @@ namespace {
2002
2002
}
2003
2003
2004
2004
void VisitDeclRefExpr (DeclRefExpr *E) {
2005
- if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl ()))
2005
+ if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl ())) {
2006
2006
if (Decls.count (VD))
2007
2007
FoundDecl = true ;
2008
+ } else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(E->getDecl ());
2009
+ MD && isLambdaCallOperator (MD)) {
2010
+ for (const auto &Capture : MD->getParent ()->captures ()) {
2011
+ if (!Capture.capturesVariable ())
2012
+ continue ;
2013
+
2014
+ if (VarDecl *VD = dyn_cast<VarDecl>(Capture.getCapturedVar ())) {
2015
+ if (Decls.count (VD))
2016
+ FoundDecl = true ;
2017
+ }
2018
+ }
2019
+ }
2020
+ }
2021
+
2022
+ void VisitCXXOperatorCallExpr (CXXOperatorCallExpr *E) {
2023
+ Visit (E->getCallee ());
2024
+
2025
+ for (auto *Arg : E->arguments ())
2026
+ Visit (Arg->IgnoreParenImpCasts ());
2008
2027
}
2009
2028
2010
2029
void VisitPseudoObjectExpr (PseudoObjectExpr *POE) {
@@ -2021,7 +2040,7 @@ namespace {
2021
2040
2022
2041
bool FoundDeclInUse () { return FoundDecl; }
2023
2042
2024
- }; // end class DeclMatcher
2043
+ }; // end class DeclMatcher
2025
2044
2026
2045
void CheckForLoopConditionalStatement (Sema &S, Expr *Second,
2027
2046
Expr *Third, Stmt *Body) {
Original file line number Diff line number Diff line change @@ -299,3 +299,18 @@ void test10() {
299
299
for (auto [i, j, k] = arr; i < a; ++i) { }
300
300
for (auto [i, j, k] = arr; i < a; ++arr[0 ]) { }
301
301
};
302
+
303
+ extern void foo (int );
304
+ void test11 () {
305
+ int a = 0 ;
306
+ auto incr_a = [&a]() { ++a; };
307
+
308
+ for (int b = 10 ; a <= b; incr_a ())
309
+ foo (a);
310
+
311
+ for (int b = 10 ; a <= b;)
312
+ incr_a ();
313
+
314
+ for (int b = 10 ; a <= b; [&a]() { ++a; }()) { }
315
+ for (int b = 10 ; a <= b; [&a]() { }()) { }
316
+ }
You can’t perform that action at this time.
0 commit comments