[PATCH] Fix ExplicitConstructorCheck to warn only on in-class declarations.

Alexander Kornienko alexfh at google.com
Wed Feb 12 09:45:03 PST 2014


Hi djasper, klimek,

I'm not absolutely sure this is 100% correct solution, but it seems to
do what I expect.

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

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
@@ -32,6 +32,8 @@
 void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
   const CXXConstructorDecl *Ctor =
       Result.Nodes.getNodeAs<CXXConstructorDecl>("construct");
+  if (Ctor != Ctor->getCanonicalDecl())
+    return;
   if (!Ctor->isExplicit() && !Ctor->isImplicit() && Ctor->getNumParams() >= 1 &&
       Ctor->getMinRequiredArguments() <= 1) {
     SourceLocation Loc = Ctor->getLocation();
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2756.1.patch
Type: text/x-patch
Size: 1164 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140212/1354190f/attachment.bin>


More information about the cfe-commits mailing list