[clang-tools-extra] r204322 - clang-tidy explicit constructor check: don't warn on copy or move constructors.

Alexander Kornienko alexfh at google.com
Thu Mar 20 02:39:36 PDT 2014


Author: alexfh
Date: Thu Mar 20 04:39:36 2014
New Revision: 204322

URL: http://llvm.org/viewvc/llvm-project?rev=204322&view=rev
Log:
clang-tidy explicit constructor check: don't warn on copy or move constructors.

Summary:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Explicit_Constructors
"The exception is copy constructors, which, in the rare cases when we allow
them, should probably not be explicit."

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D3122

Modified:
    clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
    clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp

Modified: clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp?rev=204322&r1=204321&r2=204322&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp Thu Mar 20 04:39:36 2014
@@ -34,7 +34,7 @@ void ExplicitConstructorCheck::check(con
   // Do not be confused: isExplicit means 'explicit' keyword is present,
   // isImplicit means that it's a compiler-generated constructor.
   if (Ctor->isOutOfLine() || Ctor->isExplicit() || Ctor->isImplicit() ||
-      Ctor->isDeleted())
+      Ctor->isDeleted() || Ctor->isCopyOrMoveConstructor())
     return;
   if (Ctor->getNumParams() == 0 || Ctor->getMinRequiredArguments() > 1)
     return;

Modified: clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp?rev=204322&r1=204321&r2=204322&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp Thu Mar 20 04:39:36 2014
@@ -12,8 +12,12 @@ namespace test {
 TEST(ExplicitConstructorCheckTest, SingleArgumentConstructorsOnly) {
   EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(); };");
   EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(int i, int j); };");
+  EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(const C&); };");
+  EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(C&&); };");
   EXPECT_NO_CHANGES(ExplicitConstructorCheck,
                     "class C { C(const C&) = delete; };");
+  EXPECT_NO_CHANGES(ExplicitConstructorCheck,
+                    "class C { C(int) = delete; };");
 }
 
 TEST(ExplicitConstructorCheckTest, Basic) {





More information about the cfe-commits mailing list