[clang-tidy] Simplify default member init check

Differential Revision: https://reviews.llvm.org/D97145
This commit is contained in:
Stephen Kelly 2020-12-29 13:43:34 +00:00
parent 296c6e85c1
commit 9ba557cc03
2 changed files with 11 additions and 12 deletions

View File

@ -207,14 +207,13 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
declRefExpr(to(enumConstantDecl())));
auto Init =
anyOf(initListExpr(anyOf(
allOf(initCountIs(1), hasInit(0, ignoringImplicit(InitBase))),
initCountIs(0))),
anyOf(initListExpr(anyOf(allOf(initCountIs(1), hasInit(0, InitBase)),
initCountIs(0))),
InitBase);
Finder->addMatcher(
cxxConstructorDecl(
isDefaultConstructor(), unless(isInstantiated()),
isDefaultConstructor(),
forEachConstructorInitializer(
cxxCtorInitializer(
forField(unless(anyOf(getLangOpts().CPlusPlus20
@ -222,18 +221,15 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
: isBitField(),
hasInClassInitializer(anything()),
hasParent(recordDecl(isUnion()))))),
isWritten(), withInitializer(ignoringImplicit(Init)))
withInitializer(Init))
.bind("default"))),
this);
Finder->addMatcher(
cxxConstructorDecl(
unless(ast_matchers::isTemplateInstantiation()),
forEachConstructorInitializer(
cxxCtorInitializer(forField(hasInClassInitializer(anything())),
isWritten(),
withInitializer(ignoringImplicit(Init)))
.bind("existing"))),
cxxConstructorDecl(forEachConstructorInitializer(
cxxCtorInitializer(forField(hasInClassInitializer(anything())),
withInitializer(Init))
.bind("existing"))),
this);
}

View File

@ -30,6 +30,9 @@ public:
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
return TK_IgnoreUnlessSpelledInSource;
}
private:
void checkDefaultInit(const ast_matchers::MatchFinder::MatchResult &Result,