[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

Chris Cotter via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 29 18:28:02 PST 2022


ccotter updated this revision to Diff 485655.
ccotter added a comment.

Update tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140760/new/

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -687,7 +687,7 @@
     Sum += V[I] + 2;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & I : V)
+  // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
@@ -695,7 +695,7 @@
     V[I] = 0;
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int& I : V)
+  // CHECK-FIXES: for (int & I : V)
   // CHECK-FIXES-NEXT: I = 0;
 
   // Although 'length' might be a valid free function, only std::size() is standardized
@@ -703,6 +703,14 @@
     printf("Fibonacci number is %d\n", V[I]);
     Sum += V[I] + 2;
   }
+
+  dependent<Val> Vals;
+  for (int I = 0, E = size(Vals); E != I; ++I) {
+    Sum += Vals[I].X;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & Val : Vals)
+  // CHECK-FIXES-NEXT: Sum += Val.X;
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140760.485655.patch
Type: text/x-patch
Size: 1370 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221230/213c8863/attachment.bin>


More information about the cfe-commits mailing list