[PATCH] D76549: [clang-tidy] Fix RenamerClangTidy handling qualified TypeLocs

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 21 12:15:49 PDT 2020


njames93 created this revision.
njames93 added reviewers: aaron.ballman, gribozavr2, alexfh.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Previously if a type was accessed with a qualifier, RenamerClangTidy wouldn't rename the TypeLoc, this patch addresses this shortfall by trying to find the Unqualified TypeLoc first. Also fixed a broken test case that was dependent on this broken behaviour.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76549

Files:
  clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp
@@ -57,7 +57,7 @@
 inline reference_wrapper<const Up>
 cref(const Up &u) noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: declaration uses identifier 'u', which is not a reserved identifier [bugprone-reserved-identifier]
-  // CHECK-FIXES: {{^}}cref(const Up &__u) noexcept {{{$}}
+  // CHECK-FIXES: {{^}}cref(const _Up &__u) noexcept {{{$}}
   return reference_wrapper<const Up>(u);
 }
 
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -203,14 +203,15 @@
   }
 
   if (const auto *Loc = Result.Nodes.getNodeAs<TypeLoc>("typeLoc")) {
+    auto Unqual = Loc->getUnqualifiedLoc();
     NamedDecl *Decl = nullptr;
-    if (const auto &Ref = Loc->getAs<TagTypeLoc>())
+    if (const auto &Ref = Unqual.getAs<TagTypeLoc>())
       Decl = Ref.getDecl();
-    else if (const auto &Ref = Loc->getAs<InjectedClassNameTypeLoc>())
+    else if (const auto &Ref = Unqual.getAs<InjectedClassNameTypeLoc>())
       Decl = Ref.getDecl();
-    else if (const auto &Ref = Loc->getAs<UnresolvedUsingTypeLoc>())
+    else if (const auto &Ref = Unqual.getAs<UnresolvedUsingTypeLoc>())
       Decl = Ref.getDecl();
-    else if (const auto &Ref = Loc->getAs<TemplateTypeParmTypeLoc>())
+    else if (const auto &Ref = Unqual.getAs<TemplateTypeParmTypeLoc>())
       Decl = Ref.getDecl();
     // further TypeLocs handled below
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76549.251855.patch
Type: text/x-patch
Size: 1871 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200321/adf91e40/attachment.bin>


More information about the cfe-commits mailing list