clang-tidy explicit constructors check: don't warn on deleted constructors.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 204226
This commit is contained in:
Alexander Kornienko 2014-03-19 12:48:22 +00:00
parent 2ea796e05f
commit f9a7b46ec6
3 changed files with 7 additions and 3 deletions

View File

@ -33,7 +33,8 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
// 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())
if (Ctor->isOutOfLine() || Ctor->isExplicit() || Ctor->isImplicit() ||
Ctor->isDeleted())
return;
if (Ctor->getNumParams() == 0 || Ctor->getMinRequiredArguments() > 1)
return;

View File

@ -46,13 +46,14 @@ template <typename T> std::string runCheckOnCode(StringRef Code) {
ClangTidyDiagnosticConsumer DiagConsumer(Context);
Check.setContext(&Context);
if (!tooling::runToolOnCode(new TestPPAction(Check, &Context), Code))
if (!tooling::runToolOnCodeWithArgs(new TestPPAction(Check, &Context), Code,
{"-std=c++11"}))
return "";
ast_matchers::MatchFinder Finder;
Check.registerMatchers(&Finder);
std::unique_ptr<tooling::FrontendActionFactory> Factory(
tooling::newFrontendActionFactory(&Finder));
if (!tooling::runToolOnCode(Factory->create(), Code))
if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"}))
return "";
DiagConsumer.finish();
tooling::Replacements Fixes;

View File

@ -12,6 +12,8 @@ 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&) = delete; };");
}
TEST(ExplicitConstructorCheckTest, Basic) {