diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp --- 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(const NamedDecl *Decl, SourceRange Range, SourceManager *SourceMgr) { - + Decl = cast(Decl->getCanonicalDecl()); return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(), Decl->getNameAsString()), Range, SourceMgr); @@ -376,6 +376,12 @@ if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit()) return; + const auto *Canonical = cast(Decl->getCanonicalDecl()); + if (Canonical != Decl) { + addUsage(Canonical, Decl->getLocation()); + return; + } + // Fix type aliases in value declarations. if (const auto *Value = Result.Nodes.getNodeAs("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 --- 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 @@ // 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 char const a::MyConstClass_string[] = "123"; -// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for class constant 'MyConstClass_string' // CHECK-FIXES: {{^}}char const a::kMyConstClassString[] = "123";{{$}} template