[PATCH] D16926: [clang-tidy] Fix assertion failure on `at` function in modernize-loop-convert.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 5 08:21:51 PST 2016


hokein updated this revision to Diff 47019.
hokein added a comment.

Fix a typo in doc.


http://reviews.llvm.org/D16926

Files:
  clang-tidy/modernize/LoopConvertUtils.cpp
  docs/clang-tidy/checks/modernize-loop-convert.rst
  test/clang-tidy/Inputs/modernize-loop-convert/structures.h
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===================================================================
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -251,8 +251,16 @@
   // CHECK-FIXES-NEXT: const int& Idx = Other[0];
   // CHECK-FIXES-NEXT: unsigned Othersize = Other.size();
 
+  for (int i = 0; i <  Other.size(); ++i) {
+    Other.at(i);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & i : Other)
+  // CHECK-FIXES: i;
+
   for (int I = 0, E = Dep.size(); I != E; ++I) {
     int Idx = Other.at(I);
+    Other.at(I, I);  // Should not trigger assert failure.
   }
 }
 
Index: test/clang-tidy/Inputs/modernize-loop-convert/structures.h
===================================================================
--- test/clang-tidy/Inputs/modernize-loop-convert/structures.h
+++ test/clang-tidy/Inputs/modernize-loop-convert/structures.h
@@ -98,6 +98,7 @@
   ElemType & operator[](unsigned);
   const ElemType & operator[](unsigned) const;
   ElemType & at(unsigned);
+  ElemType & at(unsigned, unsigned);
   const ElemType & at(unsigned) const;
 
   // Intentionally evil.
Index: docs/clang-tidy/checks/modernize-loop-convert.rst
===================================================================
--- docs/clang-tidy/checks/modernize-loop-convert.rst
+++ docs/clang-tidy/checks/modernize-loop-convert.rst
@@ -89,7 +89,7 @@
 
   // reasonable conversion
   for (vector<int>::iterator it = v.begin(); it != v.end(); ++it)
-    cout << *it;*
+    cout << *it;
 
   // reasonable conversion
   for (int i = 0; i < v.size(); ++i)
Index: clang-tidy/modernize/LoopConvertUtils.cpp
===================================================================
--- clang-tidy/modernize/LoopConvertUtils.cpp
+++ clang-tidy/modernize/LoopConvertUtils.cpp
@@ -391,8 +391,8 @@
     // This check is needed because getMethodDecl can return nullptr if the
     // callee is a member function pointer.
     const auto *MDecl = MemCall->getMethodDecl();
-    if (MDecl && !isa<CXXConversionDecl>(MDecl) && MDecl->getName() == "at") {
-      assert(MemCall->getNumArgs() == 1);
+    if (MDecl && !isa<CXXConversionDecl>(MDecl) && MDecl->getName() == "at" &&
+        MemCall->getNumArgs() == 1) {
       return isIndexInSubscriptExpr(MemCall->getArg(0), IndexVar);
     }
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16926.47019.patch
Type: text/x-patch
Size: 2411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160205/18677695/attachment.bin>


More information about the cfe-commits mailing list