[PATCH] D97147: [clang-tidy] Simplify redundant member init check

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 21 06:50:15 PST 2021


steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added a subscriber: xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97147

Files:
  clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h


Index: clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h
+++ clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.h
@@ -32,6 +32,9 @@
   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:
   bool IgnoreBaseInCopyConstructors;
Index: clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
@@ -26,26 +26,21 @@
 }
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
-  auto Construct =
-      cxxConstructExpr(
-          hasDeclaration(cxxConstructorDecl(hasParent(
-              cxxRecordDecl(unless(isTriviallyDefaultConstructible()))))))
-          .bind("construct");
-
   Finder->addMatcher(
-      traverse(
-          TK_AsIs,
-          cxxConstructorDecl(
-              unless(isDelegatingConstructor()),
-              ofClass(unless(
-                  anyOf(isUnion(), ast_matchers::isTemplateInstantiation()))),
-              forEachConstructorInitializer(
-                  cxxCtorInitializer(
-                      isWritten(), withInitializer(ignoringImplicit(Construct)),
-                      unless(forField(hasType(isConstQualified()))),
-                      unless(forField(hasParent(recordDecl(isUnion())))))
-                      .bind("init")))
-              .bind("constructor")),
+      cxxConstructorDecl(
+          unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
+          forEachConstructorInitializer(
+              cxxCtorInitializer(
+                  withInitializer(
+                      cxxConstructExpr(
+                          hasDeclaration(
+                              cxxConstructorDecl(ofClass(cxxRecordDecl(
+                                  unless(isTriviallyDefaultConstructible()))))))
+                          .bind("construct")),
+                  unless(forField(hasType(isConstQualified()))),
+                  unless(forField(hasParent(recordDecl(isUnion())))))
+                  .bind("init")))
+          .bind("constructor"),
       this);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97147.325295.patch
Type: text/x-patch
Size: 2658 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210221/630f337d/attachment.bin>


More information about the cfe-commits mailing list