[PATCH] D22513: [clang-tidy] add check cppcoreguidelines-rule-of-five-and-zero
Piotr Padlewski via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 22 13:36:11 PDT 2016
Prazek added a comment.
I will look again soon, but it looks much better right now!
================
Comment at: clang-tidy/cppcoreguidelines/RuleOfFiveAndZeroCheck.cpp:43-57
@@ +42,17 @@
+
+llvm::StringRef RuleOfFiveAndZeroCheck::toString(
+ RuleOfFiveAndZeroCheck::SpecialMemberFunctionKind K) {
+ switch (K) {
+ case SpecialMemberFunctionKind::Destructor:
+ return "a destructor";
+ case SpecialMemberFunctionKind::CopyConstructor:
+ return "a copy constructor";
+ case SpecialMemberFunctionKind::CopyAssignment:
+ return "a copy assignment operator";
+ case SpecialMemberFunctionKind::MoveConstructor:
+ return "a move constructor";
+ case SpecialMemberFunctionKind::MoveAssignment:
+ return "a move assignment operator";
+ }
+}
+
----------------
maybe make it a DenseMap? (or maybe there is SmallMap or SmallDense map or something similar)
================
Comment at: clang-tidy/cppcoreguidelines/RuleOfFiveAndZeroCheck.cpp:85-105
@@ +84,23 @@
+
+ if (Result.Nodes.getNodeAs<CXXDestructorDecl>("dtor")) {
+ ClassWithSpecialMembers[ID].push_back(
+ SpecialMemberFunctionKind::Destructor);
+ }
+ if (Result.Nodes.getNodeAs<CXXConstructorDecl>("copy-ctor")) {
+ ClassWithSpecialMembers[ID].push_back(
+ SpecialMemberFunctionKind::CopyConstructor);
+ }
+ if (Result.Nodes.getNodeAs<CXXMethodDecl>("copy-assign")) {
+ ClassWithSpecialMembers[ID].push_back(
+ SpecialMemberFunctionKind::CopyAssignment);
+ }
+ if (Result.Nodes.getNodeAs<CXXConstructorDecl>("move-ctor")) {
+ ClassWithSpecialMembers[ID].push_back(
+ SpecialMemberFunctionKind::MoveConstructor);
+ }
+ if (Result.Nodes.getNodeAs<CXXMethodDecl>("move-assign")) {
+ ClassWithSpecialMembers[ID].push_back(
+ SpecialMemberFunctionKind::MoveAssignment);
+ }
+}
+
----------------
This looks like it could be changed into for
for (auto [str, kind] : kinds) {
if( ... Result.Nodes.getNodeAs<FunctionDecl>(str))
I havent tried putting Base type to getNodeAs, but I think it should work.
https://reviews.llvm.org/D22513
More information about the cfe-commits
mailing list