CheckClass: Tweak rule of 3 checker
This commit is contained in:
parent
5518247b96
commit
485d3e0229
|
@ -2427,10 +2427,10 @@ void CheckClass::checkRuleOf3()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// all 3 methods are defined
|
// all 3 methods are defined
|
||||||
if (copyCtor == CtorType::WITH_BODY && assignmentOperator == CtorType::WITH_BODY && destructor)
|
if (copyCtor != CtorType::NO && assignmentOperator != CtorType::NO && destructor)
|
||||||
continue;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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());
|
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"
|
checkRuleOf3("class A {\n"
|
||||||
" A& operator=(const int &x) { this->x = x; return *this; }\n"
|
" A& operator=(const int &x) { this->x = x; return *this; }\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
|
Loading…
Reference in New Issue