[clang-tidy] Fix "Name is not a simple identifier" assertion in `modernize-loop-conve...
authorHaojian Wu <hokein@google.com>
Mon, 14 Mar 2016 12:41:24 +0000 (12:41 +0000)
committerHaojian Wu <hokein@google.com>
Mon, 14 Mar 2016 12:41:24 +0000 (12:41 +0000)
Summary:
Fix assertion failure: "Name is not a simple identifier".

`Decl::GetName` assumes the name should be an identifier. When the check
processes the function calling statement with speciail key name like
'it.operator->()', it will trigger the assert in `GetName`.

Rather than using `Decl::GetName`, we use `getNameAsString` which works
with special key names in C++.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18141

llvm-svn: 263426

clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp

index 03f8583..5894a8b 100644 (file)
@@ -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" &&
-        MemCall->getNumArgs() == 1) {
+    if (MDecl && !isa<CXXConversionDecl>(MDecl) &&
+        MDecl->getNameAsString() == "at" && MemCall->getNumArgs() == 1) {
       return isIndexInSubscriptExpr(MemCall->getArg(0), IndexVar);
     }
     return false;
index cc5b8af..def7c4b 100644 (file)
@@ -320,6 +320,10 @@ void f() {
   // CHECK-FIXES: for (auto & It : Uu)
   // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
 
+  for (U::iterator It = Uu.begin(), E = Uu.end(); It != E; ++It) {
+    Val* a = It.operator->();
+  }
+
   U::iterator A;
   for (U::iterator I = Uu.begin(), E = Uu.end(); I != E; ++I)
     int K = A->X + I->X;