[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
Mon Feb 8 08:05:24 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL260107: [clang-tidy] Fix assertion failure on `at` function in modernize-loop-convert. (authored by hokein).
Changed prior to commit:
http://reviews.llvm.org/D16926?vs=47019&id=47204#toc
Repository:
rL LLVM
http://reviews.llvm.org/D16926
Files:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
Index: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
+++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
+++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
+++ clang-tools-extra/trunk/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;
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst
===================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst
+++ clang-tools-extra/trunk/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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16926.47204.patch
Type: text/x-patch
Size: 2699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160208/b778140d/attachment-0001.bin>
More information about the cfe-commits
mailing list