aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2018-01-08 23:51:48 +0000
committerSergio Martins <smartins@kde.org>2018-01-08 23:51:48 +0000
commit451664d8726b176e23f9bbef9d61d21073f0f198 (patch)
tree3c3093017d98ff6c9e3bce2ea751b9617d5ff12a /src
parent0e86a561361f1cafc2680d3966cd126c5cd9034e (diff)
rule-of-three: Improve last commit
Now it also fixes the second bug Our previous fix wasn't being run because it was in the if (numImplemeted == 1), so failed for the case where we have a user-dtor, user-copy-ctor and deleted-copy-assign. Moving the check out of the if fixes it. BUG: 388682
Diffstat (limited to 'src')
-rw-r--r--src/checks/level2/ruleofthree.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/checks/level2/ruleofthree.cpp b/src/checks/level2/ruleofthree.cpp
index 3794d5ac..3baf85ff 100644
--- a/src/checks/level2/ruleofthree.cpp
+++ b/src/checks/level2/ruleofthree.cpp
@@ -67,6 +67,17 @@ void RuleOfThree::VisitDecl(clang::Decl *decl)
//const bool hasMoveCtor = record->hasNonTrivialMoveConstructor();
//const bool hasTrivialMoveAssignment = record->hasNonTrivialMoveAssignment();
+
+ const bool copyCtorIsDeleted = copyCtor && copyCtor->isDeleted();
+ const bool copyAssignIsDeleted = copyAssign && copyAssign->isDeleted();
+
+ if (hasUserDtor && (copyCtorIsDeleted || copyAssignIsDeleted)) {
+ // One of the copy methods was explicitely deleted, it's safe.
+ // The case we want to catch is when one is user-written and the other is
+ // compiler-generated.
+ return;
+ }
+
const int numImplemented = hasUserCopyCtor + hasUserCopyAssign + hasUserDtor;
if (numImplemented == 0 || numImplemented == 3) // Rule of 3 respected
return;
@@ -101,12 +112,6 @@ void RuleOfThree::VisitDecl(clang::Decl *decl)
if (destructor->getAccess() == clang::AccessSpecifier::AS_protected)
return;
- const bool copyCtorIsDeleted = copyCtor && copyCtor->isDeleted();
- const bool copyAssignIsDeleted = copyAssign && copyAssign->isDeleted();
-
- if (copyCtorIsDeleted || copyAssignIsDeleted) // One of them was explicitely deleted, it's safe.
- return;
-
if (Utils::functionHasEmptyBody(destructor)) {
// Lets reduce noise and allow the empty dtor. In theory we could warn, but there's no
// hidden bug behind this dummy dtor.