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
 


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
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to