diff options
author | Nathan James <n.james93@hotmail.co.uk> | 2020-01-13 13:26:58 -0500 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2020-01-13 13:28:55 -0500 |
commit | fb79ef524171c96a9f3df025ac7a8a3e00fdc0b4 (patch) | |
tree | 784a63f5b32c9a47289b3a6b2e8d49b410fcab45 /clang-tools-extra/clang-tidy | |
parent | a2cd4fe6bf2a4e37d5f69b0b19cb1134a14e2970 (diff) | |
download | bcm5719-llvm-fb79ef524171c96a9f3df025ac7a8a3e00fdc0b4.tar.gz bcm5719-llvm-fb79ef524171c96a9f3df025ac7a8a3e00fdc0b4.zip |
Fix readability-identifier-naming missing member variables
Fixes PR41122 (missing fixes for member variables in a destructor) and
PR29005 (does not rename class members in all locations).
Diffstat (limited to 'clang-tools-extra/clang-tidy')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp index bd736743ae1..8146cb36cf2 100644 --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -237,10 +237,26 @@ void IdentifierNamingCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(namedDecl().bind("decl"), this); Finder->addMatcher(usingDecl().bind("using"), this); Finder->addMatcher(declRefExpr().bind("declRef"), this); - Finder->addMatcher(cxxConstructorDecl().bind("classRef"), this); - Finder->addMatcher(cxxDestructorDecl().bind("classRef"), this); + Finder->addMatcher(cxxConstructorDecl(unless(isImplicit())).bind("classRef"), + this); + Finder->addMatcher(cxxDestructorDecl(unless(isImplicit())).bind("classRef"), + this); Finder->addMatcher(typeLoc().bind("typeLoc"), this); Finder->addMatcher(nestedNameSpecifierLoc().bind("nestedNameLoc"), this); + Finder->addMatcher( + functionDecl(unless(cxxMethodDecl(isImplicit())), + hasBody(forEachDescendant(memberExpr().bind("memberExpr")))), + this); + Finder->addMatcher( + cxxConstructorDecl( + unless(isImplicit()), + forEachConstructorInitializer( + allOf(isWritten(), withInitializer(forEachDescendant( + memberExpr().bind("memberExpr")))))), + this); + Finder->addMatcher(fieldDecl(hasInClassInitializer( + forEachDescendant(memberExpr().bind("memberExpr")))), + this); } void IdentifierNamingCheck::registerPPCallbacks( @@ -710,8 +726,6 @@ static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap &Failures, void IdentifierNamingCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *Decl = Result.Nodes.getNodeAs<CXXConstructorDecl>("classRef")) { - if (Decl->isImplicit()) - return; addUsage(NamingCheckFailures, Decl->getParent(), Decl->getNameInfo().getSourceRange()); @@ -730,8 +744,6 @@ void IdentifierNamingCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *Decl = Result.Nodes.getNodeAs<CXXDestructorDecl>("classRef")) { - if (Decl->isImplicit()) - return; SourceRange Range = Decl->getNameInfo().getSourceRange(); if (Range.getBegin().isInvalid()) @@ -806,6 +818,14 @@ void IdentifierNamingCheck::check(const MatchFinder::MatchResult &Result) { return; } + if (const auto *MemberRef = + Result.Nodes.getNodeAs<MemberExpr>("memberExpr")) { + SourceRange Range = MemberRef->getMemberNameInfo().getSourceRange(); + addUsage(NamingCheckFailures, MemberRef->getMemberDecl(), Range, + Result.SourceManager); + return; + } + if (const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>("decl")) { if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit()) return; |