Skip to content

Commit

Permalink
CheckClass: Tweak rule of 3 checker
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Apr 24, 2018
1 parent 5518247 commit 485d3e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/checkclass.cpp
Expand Up @@ -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);
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/testclass.cpp
Expand Up @@ -244,6 +244,12 @@ class TestClass : public TestFixture {
"};");
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"
Expand Down

0 comments on commit 485d3e0

Please sign in to comment.