Skip to content

Commit 35763ba

Browse files
committed
[clang-tidy] Simplify redundant member init check
Differential Revision: https://reviews.llvm.org/D97147
1 parent 9ba557c commit 35763ba

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,21 @@ void RedundantMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2626
}
2727

2828
void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
29-
auto Construct =
30-
cxxConstructExpr(
31-
hasDeclaration(cxxConstructorDecl(hasParent(
32-
cxxRecordDecl(unless(isTriviallyDefaultConstructible()))))))
33-
.bind("construct");
34-
3529
Finder->addMatcher(
36-
traverse(
37-
TK_AsIs,
38-
cxxConstructorDecl(
39-
unless(isDelegatingConstructor()),
40-
ofClass(unless(
41-
anyOf(isUnion(), ast_matchers::isTemplateInstantiation()))),
42-
forEachConstructorInitializer(
43-
cxxCtorInitializer(
44-
isWritten(), withInitializer(ignoringImplicit(Construct)),
45-
unless(forField(hasType(isConstQualified()))),
46-
unless(forField(hasParent(recordDecl(isUnion())))))
47-
.bind("init")))
48-
.bind("constructor")),
30+
cxxConstructorDecl(
31+
unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
32+
forEachConstructorInitializer(
33+
cxxCtorInitializer(
34+
withInitializer(
35+
cxxConstructExpr(
36+
hasDeclaration(
37+
cxxConstructorDecl(ofClass(cxxRecordDecl(
38+
unless(isTriviallyDefaultConstructible()))))))
39+
.bind("construct")),
40+
unless(forField(hasType(isConstQualified()))),
41+
unless(forField(hasParent(recordDecl(isUnion())))))
42+
.bind("init")))
43+
.bind("constructor"),
4944
this);
5045
}
5146

clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class RedundantMemberInitCheck : public ClangTidyCheck {
3232
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
3333
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3434
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35+
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
36+
return TK_IgnoreUnlessSpelledInSource;
37+
}
3538

3639
private:
3740
bool IgnoreBaseInCopyConstructors;

0 commit comments

Comments
 (0)