Author: Nathan James Date: 2020-06-18T15:50:16+01:00 New Revision: 850bb889a56ccf3252792c6d3db59542e94753ae
URL: https://github.com/llvm/llvm-project/commit/850bb889a56ccf3252792c6d3db59542e94753ae DIFF: https://github.com/llvm/llvm-project/commit/850bb889a56ccf3252792c6d3db59542e94753ae.diff LOG: [clang-tidy] RenamerClangTidy group redecls into 1 warning. This changes the behavious of `RenamerClangTidyCheck` based checks by grouping declarations of the same thing into 1 warning where it is first declared. This cleans up clang-tidy output and prevents issues where 1 fix-it couldn't be applied, yet all other warnings(and fix-its) for the same declaration would be applied. The old behaviour of forward declaring a class without defining it isn't affected, i.e. no warnings will be emitted for that case. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D82059 Added: Modified: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.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 03bece233240..e90ab1782b4b 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -168,7 +168,7 @@ void RenamerClangTidyCheck::addUsage( void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range, SourceManager *SourceMgr) { - + Decl = cast<NamedDecl>(Decl->getCanonicalDecl()); return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), Decl->getNameAsString()), Range, SourceMgr); @@ -376,6 +376,12 @@ void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) { if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit()) return; + const auto *Canonical = cast<NamedDecl>(Decl->getCanonicalDecl()); + if (Canonical != Decl) { + addUsage(Canonical, Decl->getLocation()); + return; + } + // Fix type aliases in value declarations. if (const auto *Value = Result.Nodes.getNodeAs<ValueDecl>("decl")) { if (const Type *TypePtr = Value->getType().getTypePtrOrNull()) { 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 1bb435e02eb5..3a3bfecc01fc 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 @@ -214,17 +214,16 @@ class my_class { // CHECK-FIXES: {{^}} static int ClassMember2;{{$}} }; class my_class; -// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_class' +// No warning needed here as this is tied to the previous declaration. +// Just make sure the fix is applied. // CHECK-FIXES: {{^}}class CMyClass;{{$}} class my_forward_declared_class; // No warning should be triggered. const int my_class::classConstant = 4; -// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for class constant 'classConstant' // CHECK-FIXES: {{^}}const int CMyClass::kClassConstant = 4;{{$}} int my_class::ClassMember_2 = 5; -// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for class member 'ClassMember_2' // CHECK-FIXES: {{^}}int CMyClass::ClassMember2 = 5;{{$}} class my_derived_class : public virtual my_class {}; @@ -500,7 +499,6 @@ template <typename t_t> struct a { template<typename t_t> char const a<t_t>::MyConstClass_string[] = "123"; -// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for class constant 'MyConstClass_string' // CHECK-FIXES: {{^}}char const a<t_t>::kMyConstClassString[] = "123";{{$}} template <template <typename> class A> struct b { A<int> c; }; @@ -545,3 +543,22 @@ void QualifiedTypeLocTest(const THIS___Structure &); // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure &);{{$}} void QualifiedTypeLocTest(volatile THIS___Structure &); // CHECK-FIXES: {{^}}void QualifiedTypeLocTest(volatile this_structure &);{{$}} + +namespace redecls { +// We only want the warning to show up once here for the first decl. +// CHECK-MESSAGES: :[[@LINE+1]]:6: warning: invalid case style for global function 'badNamedFunction' +void badNamedFunction(); +void badNamedFunction(); +void badNamedFunction(){} +// CHECK-FIXES: {{^}}void BadNamedFunction(); +// CHECK-FIXES-NEXT: {{^}}void BadNamedFunction(); +// CHECK-FIXES-NEXT: {{^}}void BadNamedFunction(){} +void ReferenceBadNamedFunction() { + auto l_Ptr = badNamedFunction; + // CHECK-FIXES: {{^}} auto l_Ptr = BadNamedFunction; + l_Ptr(); + badNamedFunction(); + // CHECK-FIXES: {{^}} BadNamedFunction(); +} + +} // namespace redecls _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits