[clang-tools-extra] r260107 - [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 07:59:42 PST 2016
Author: hokein
Date: Mon Feb 8 09:59:42 2016
New Revision: 260107
URL: http://llvm.org/viewvc/llvm-project?rev=260107&view=rev
Log:
[clang-tidy] Fix assertion failure on `at` function in modernize-loop-convert.
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D16926
Modified:
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
Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=260107&r1=260106&r2=260107&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Mon Feb 8 09:59:42 2016
@@ -391,8 +391,8 @@ static bool isAliasDecl(ASTContext *Cont
// 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;
Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst?rev=260107&r1=260106&r2=260107&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst Mon Feb 8 09:59:42 2016
@@ -89,7 +89,7 @@ Original:
// 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)
Modified: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h?rev=260107&r1=260106&r2=260107&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h (original)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-loop-convert/structures.h Mon Feb 8 09:59:42 2016
@@ -98,6 +98,7 @@ class dependent {
ElemType & operator[](unsigned);
const ElemType & operator[](unsigned) const;
ElemType & at(unsigned);
+ ElemType & at(unsigned, unsigned);
const ElemType & at(unsigned) const;
// Intentionally evil.
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp?rev=260107&r1=260106&r2=260107&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp Mon Feb 8 09:59:42 2016
@@ -251,8 +251,16 @@ void refs_and_vals() {
// 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.
}
}
More information about the cfe-commits
mailing list