Author: Nathan James Date: 2020-03-23T13:45:34Z New Revision: 7693a9b9314083eafd9b5b1e19b02aac06962eb2
URL: https://github.com/llvm/llvm-project/commit/7693a9b9314083eafd9b5b1e19b02aac06962eb2 DIFF: https://github.com/llvm/llvm-project/commit/7693a9b9314083eafd9b5b1e19b02aac06962eb2.diff LOG: [clang-tidy] Fix RenamerClangTidy handling qualified TypeLocs Summary: 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. Example: ``` struct a{}; void foo(const a&); void foo(a&); void foo(a); void foo(a&&); void foo(const a); ``` exec `-checks=readability-identifier-naming --config="{CheckOptions: [{key: readability-identifier-naming.StructCase, value: CamelCase}]}" -fix` Current Behaviour: ``` struct A{}; void foo(const a&); void foo(A&); void foo(A); void foo(A&&); void foo(const a); ``` Proposed new behaviour: ``` struct A{}; void foo(const A&); void foo(A&); void foo(A); void foo(A&&); void foo(const A); ``` Reviewers: aaron.ballman, gribozavr2, alexfh Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76549 Added: Modified: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 21d304e1a438..3523cf5dcf16 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -203,14 +203,15 @@ void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) { } if (const auto *Loc = Result.Nodes.getNodeAs<TypeLoc>("typeLoc")) { + UnqualTypeLoc 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 diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp index f8a2662bebf1..501f6dd13dc5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp @@ -57,7 +57,7 @@ template <class Up> 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); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp index 908281391064..7983bb30ca64 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp @@ -532,3 +532,16 @@ using namespace FOO_NS; using namespace FOO_NS::InlineNamespace; // CHECK-FIXES: {{^}}using namespace foo_ns::inline_namespace; + +void QualifiedTypeLocTest(THIS___Structure); +// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure);{{$}} +void QualifiedTypeLocTest(THIS___Structure &); +// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &);{{$}} +void QualifiedTypeLocTest(THIS___Structure &&); +// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &&);{{$}} +void QualifiedTypeLocTest(const THIS___Structure); +// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure);{{$}} +void QualifiedTypeLocTest(const THIS___Structure &); +// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure &);{{$}} +void QualifiedTypeLocTest(volatile THIS___Structure &); +// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(volatile this_structure &);{{$}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits