CheckClass: Tweak rule of 3 checker

This commit is contained in:
Daniel Marjamäki 2018-04-24 21:45:30 +02:00
parent 5518247b96
commit 485d3e0229
2 changed files with 8 additions and 2 deletions

View File

@ -2427,10 +2427,10 @@ void CheckClass::checkRuleOf3()
continue;
// all 3 methods are defined
if (copyCtor == CtorType::WITH_BODY && assignmentOperator == CtorType::WITH_BODY && destructor)
if (copyCtor != CtorType::NO && assignmentOperator != CtorType::NO && destructor)
continue;
ruleOf3Error(scope->classDef, scope->className, scope->type == Scope::eStruct, copyCtor == CtorType::WITH_BODY, assignmentOperator == CtorType::WITH_BODY, destructor);
ruleOf3Error(scope->classDef, scope->className, scope->type == Scope::eStruct, copyCtor != CtorType::NO, assignmentOperator != CtorType::NO, destructor);
}
}

View File

@ -244,6 +244,12 @@ private:
"};");
ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' defines 'operator=' but does not define 'copy constructor' and 'destructor'\n", errout.str());
checkRuleOf3("class A {\n"
" ~A() { }\n"
" int x;\n"
"};");
ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' defines 'destructor' but does not define 'copy constructor' and 'operator='\n", errout.str());
checkRuleOf3("class A {\n"
" A& operator=(const int &x) { this->x = x; return *this; }\n"
" int x;\n"