[PATCH] D21134: clang-tidy: new check readability-misplaced-array-index

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 16 09:32:57 PDT 2016


alexfh requested changes to this revision.
This revision now requires changes to proceed.

================
Comment at: clang-tidy/readability/MisplacedArrayIndexCheck.cpp:56
@@ +55,3 @@
+  if (hasMacroID(ArraySubscriptE) ||
+      !Result.SourceManager->isWrittenInSameFile(ArraySubscriptE->getLocStart(),
+                                                 ArraySubscriptE->getLocEnd()))
----------------
Both ranges seem to be using `ArraySubscriptE->getLHS()->getSourceRange()`. I guess, the second one should refer to `ArraySubscriptE->getRHS()->getSourceRange()` instead?

================
Comment at: docs/clang-tidy/checks/readability-misplaced-array-index.rst:12
@@ +11,3 @@
+
+  void f(int *x, int y)
+  {
----------------
Please format examples according to LLVM style (specifically, leave braces at the end of the previous line.

================
Comment at: test/clang-tidy/readability-misplaced-array-index.cpp:16
@@ +15,3 @@
+  10[xy->x] = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: confusing array subscript expression, usually the index is inside the []
+  // CHECK-FIXES: xy->x[10] = 0;
----------------
Please truncate all CHECK-MESSAGES except for the first one after "confusing array subscript expression".

================
Comment at: test/clang-tidy/readability-misplaced-array-index.cpp:25
@@ +24,3 @@
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression, usually the index is inside the []
+  // No fixit, we don't want to replace with "abc"[1]
+
----------------
Please add a CHECK-FIXES to verify the original code is left intact. Same for other places where no fixits are expected.


https://reviews.llvm.org/D21134





More information about the cfe-commits mailing list