summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp4
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst2
-rw-r--r--clang-tools-extra/test/clang-tidy/Inputs/modernize-loop-convert/structures.h1
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp8
4 files changed, 12 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index c50e9238170..b3dfa93d67c 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -391,8 +391,8 @@ static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl,
// 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;
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
index e65c9e59bcd..9ef9772fda1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
@@ -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)
diff --git a/clang-tools-extra/test/clang-tidy/Inputs/modernize-loop-convert/structures.h b/clang-tools-extra/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
index 6eecae97ee4..02d440c21a5 100644
--- a/clang-tools-extra/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
+++ b/clang-tools-extra/test/clang-tidy/Inputs/modernize-loop-convert/structures.h
@@ -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.
diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
index 42796f22710..7312b48b9b3 100644
--- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
+++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -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.
}
}
OpenPOWER on IntegriCloud