[PATCH] D97145: [clang-tidy] Simplify default member init check

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 21 06:44:04 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/D97145

Files:
  clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h


Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.h
@@ -30,6 +30,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:
   void checkDefaultInit(const ast_matchers::MatchFinder::MatchResult &Result,
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -207,14 +207,13 @@
             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 @@
                                             : 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);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97145.325292.patch
Type: text/x-patch
Size: 2741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210221/d2ccafc5/attachment-0001.bin>


More information about the cfe-commits mailing list