njames93 updated this revision to Diff 271509. njames93 added a comment. New line...
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82059/new/ https://reviews.llvm.org/D82059 Files: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp @@ -214,17 +214,16 @@ // 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> 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 @@ // 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 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 @@ -168,7 +168,7 @@ 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); @@ -380,6 +380,14 @@ 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()) {
Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp @@ -214,17 +214,16 @@ // 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> 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 @@ // 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 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 @@ -168,7 +168,7 @@ 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); @@ -380,6 +380,14 @@ 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()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits