Use the new isOutOfLine, isImplicit, and isExplicit matchers.

Hi djasper, klimek,

http://llvm-reviews.chandlerc.com/D2756

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2756?vs=7032&id=7049#toc

Files:
  clang-tidy/google/GoogleTidyModule.cpp
  unittests/clang-tidy/GoogleModuleTest.cpp

Index: clang-tidy/google/GoogleTidyModule.cpp
===================================================================
--- clang-tidy/google/GoogleTidyModule.cpp
+++ clang-tidy/google/GoogleTidyModule.cpp
@@ -26,14 +26,16 @@
 
 void
 ExplicitConstructorCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
-  Finder->addMatcher(constructorDecl().bind("construct"), this);
+  Finder->addMatcher(constructorDecl(unless(isOutOfLine()),
+                                     unless(isImplicit()),
+                                     unless(isExplicit())).bind("construct"),
+                     this);
 }
 
 void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
   const CXXConstructorDecl *Ctor =
       Result.Nodes.getNodeAs<CXXConstructorDecl>("construct");
-  if (!Ctor->isExplicit() && !Ctor->isImplicit() && Ctor->getNumParams() >= 1 
&&
-      Ctor->getMinRequiredArguments() <= 1) {
+  if (Ctor->getNumParams() >= 1 && Ctor->getMinRequiredArguments() <= 1) {
     SourceLocation Loc = Ctor->getLocation();
     diag(Loc, "Single-argument constructors must be explicit")
         << FixItHint::CreateInsertion(Loc, "explicit ");
Index: unittests/clang-tidy/GoogleModuleTest.cpp
===================================================================
--- unittests/clang-tidy/GoogleModuleTest.cpp
+++ unittests/clang-tidy/GoogleModuleTest.cpp
@@ -21,5 +21,10 @@
             runCheckOn("class C { C(int i, int j = 0); };"));
 }
 
+TEST_F(ExplicitConstructorCheckTest, OutOfLineDefinitions) {
+  EXPECT_EQ("class C { explicit C(int i); }; C::C(int i) {}",
+            runCheckOn("class C { C(int i); }; C::C(int i) {}"));
+}
+
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/google/GoogleTidyModule.cpp
===================================================================
--- clang-tidy/google/GoogleTidyModule.cpp
+++ clang-tidy/google/GoogleTidyModule.cpp
@@ -26,14 +26,16 @@
 
 void
 ExplicitConstructorCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
-  Finder->addMatcher(constructorDecl().bind("construct"), this);
+  Finder->addMatcher(constructorDecl(unless(isOutOfLine()),
+                                     unless(isImplicit()),
+                                     unless(isExplicit())).bind("construct"),
+                     this);
 }
 
 void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
   const CXXConstructorDecl *Ctor =
       Result.Nodes.getNodeAs<CXXConstructorDecl>("construct");
-  if (!Ctor->isExplicit() && !Ctor->isImplicit() && Ctor->getNumParams() >= 1 &&
-      Ctor->getMinRequiredArguments() <= 1) {
+  if (Ctor->getNumParams() >= 1 && Ctor->getMinRequiredArguments() <= 1) {
     SourceLocation Loc = Ctor->getLocation();
     diag(Loc, "Single-argument constructors must be explicit")
         << FixItHint::CreateInsertion(Loc, "explicit ");
Index: unittests/clang-tidy/GoogleModuleTest.cpp
===================================================================
--- unittests/clang-tidy/GoogleModuleTest.cpp
+++ unittests/clang-tidy/GoogleModuleTest.cpp
@@ -21,5 +21,10 @@
             runCheckOn("class C { C(int i, int j = 0); };"));
 }
 
+TEST_F(ExplicitConstructorCheckTest, OutOfLineDefinitions) {
+  EXPECT_EQ("class C { explicit C(int i); }; C::C(int i) {}",
+            runCheckOn("class C { C(int i); }; C::C(int i) {}"));
+}
+
 } // namespace tidy
 } // namespace clang
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to