Expose the clang-tidy misc-assign-operator-signature checker as cppcoreguidelines-c-copy-assignment-signature.

llvm-svn: 250165
This commit is contained in:
Aaron Ballman 2015-10-13 15:24:33 +00:00
parent f420dda18d
commit 17b6feef69
3 changed files with 15 additions and 6 deletions

View File

@ -10,6 +10,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "../misc/AssignOperatorSignatureCheck.h"
#include "ProBoundsPointerArithmeticCheck.h"
#include "ProTypeConstCastCheck.h"
#include "ProTypeReinterpretCastCheck.h"
@ -31,6 +32,8 @@ public:
"cppcoreguidelines-pro-type-reinterpret-cast");
CheckFactories.registerCheck<ProTypeStaticCastDowncastCheck>(
"cppcoreguidelines-pro-type-static-cast-downcast");
CheckFactories.registerCheck<misc::AssignOperatorSignatureCheck>(
"cppcoreguidelines-c-copy-assignment-signature");
}
};

View File

@ -51,11 +51,11 @@ void AssignOperatorSignatureCheck::registerMatchers(
.bind("ArgumentType"),
this);
Finder->addMatcher(cxxMethodDecl(IsSelfAssign, isConst()).bind("Const"),
this);
Finder->addMatcher(
cxxMethodDecl(IsSelfAssign, anyOf(isConst(), isVirtual())).bind("cv"),
this);
}
void AssignOperatorSignatureCheck::check(
const MatchFinder::MatchResult &Result) {
const auto* Method = Result.Nodes.getNodeAs<CXXMethodDecl>("method");
@ -64,12 +64,13 @@ void AssignOperatorSignatureCheck::check(
static const char *Messages[][2] = {
{"ReturnType", "operator=() should return '%0&'"},
{"ArgumentType", "operator=() should take '%0 const&', '%0&&' or '%0'"},
{"Const", "operator=() should not be marked 'const'"},
{"cv", "operator=() should not be marked '%1'"}
};
for (const auto& Message : Messages) {
for (const auto &Message : Messages) {
if (Result.Nodes.getNodeAs<Decl>(Message[0]))
diag(Method->getLocStart(), Message[1]) << Name;
diag(Method->getLocStart(), Message[1])
<< Name << (Method->isConst() ? "const" : "virtual");
}
}

View File

@ -49,3 +49,8 @@ class Private {
// Pre-C++11 way of disabling assignment.
void operator=(const Private &);
};
struct Virtual {
virtual Virtual& operator=(const Virtual &);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should not be marked 'virtual'
};