[clang-tools-extra] r263426 - [clang-tidy] Fix "Name is not a simple identifier" assertion in `modernize-loop-convert` check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 14 05:41:25 PDT 2016


Author: hokein
Date: Mon Mar 14 07:41:24 2016
New Revision: 263426

URL: http://llvm.org/viewvc/llvm-project?rev=263426&view=rev
Log:
[clang-tidy] Fix "Name is not a simple identifier" assertion in `modernize-loop-convert` check.

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

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.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=263426&r1=263425&r2=263426&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Mon Mar 14 07:41:24 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" &&
-        MemCall->getNumArgs() == 1) {
+    if (MDecl && !isa<CXXConversionDecl>(MDecl) &&
+        MDecl->getNameAsString() == "at" && MemCall->getNumArgs() == 1) {
       return isIndexInSubscriptExpr(MemCall->getArg(0), IndexVar);
     }
     return false;

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp?rev=263426&r1=263425&r2=263426&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp Mon Mar 14 07:41:24 2016
@@ -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;




More information about the cfe-commits mailing list