Alexander Kornienko f65a549a82 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

llvm-svn: 204322
2014-03-20 09:39:36 +00:00

43 lines
1.5 KiB
C++

#include "ClangTidyTest.h"
#include "google/GoogleTidyModule.h"
#include "gtest/gtest.h"
namespace clang {
namespace tidy {
namespace test {
#define EXPECT_NO_CHANGES(Check, Code) \
EXPECT_EQ(Code, runCheckOnCode<Check>(Code))
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) {
EXPECT_EQ("class C { explicit C(int i); };",
runCheckOnCode<ExplicitConstructorCheck>("class C { C(int i); };"));
}
TEST(ExplicitConstructorCheckTest, DefaultParameters) {
EXPECT_EQ("class C { explicit C(int i, int j = 0); };",
runCheckOnCode<ExplicitConstructorCheck>(
"class C { C(int i, int j = 0); };"));
}
TEST(ExplicitConstructorCheckTest, OutOfLineDefinitions) {
EXPECT_EQ("class C { explicit C(int i); }; C::C(int i) {}",
runCheckOnCode<ExplicitConstructorCheck>(
"class C { C(int i); }; C::C(int i) {}"));
}
} // namespace test
} // namespace tidy
} // namespace clang