[clang-tools-extra] r250165 - Expose the clang-tidy misc-assign-operator-signature checker as cppcoreguidelines-c-copy-assignment-signature.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 13 08:24:33 PDT 2015
Author: aaronballman
Date: Tue Oct 13 10:24:33 2015
New Revision: 250165
URL: http://llvm.org/viewvc/llvm-project?rev=250165&view=rev
Log:
Expose the clang-tidy misc-assign-operator-signature checker as cppcoreguidelines-c-copy-assignment-signature.
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp
Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=250165&r1=250164&r2=250165&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp Tue Oct 13 10:24:33 2015
@@ -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");
}
};
Modified: clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp?rev=250165&r1=250164&r2=250165&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/AssignOperatorSignatureCheck.cpp Tue Oct 13 10:24:33 2015
@@ -51,11 +51,11 @@ void AssignOperatorSignatureCheck::regis
.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");
}
}
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp?rev=250165&r1=250164&r2=250165&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-assign-operator-signature.cpp Tue Oct 13 10:24:33 2015
@@ -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'
+};
More information about the cfe-commits
mailing list