Fix false positive about return type when there's =delete in operator= declaration

This commit is contained in:
Dmitry-Me 2014-11-25 15:52:52 +01:00 committed by Daniel Marjamäki
parent 9233e79390
commit f926958acb
2 changed files with 24 additions and 0 deletions

View File

@ -1118,6 +1118,9 @@ void CheckClass::operatorEq()
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
if (func->type == Function::eOperatorEqual && func->access != Private) {
// skip if there's =delete in the declaration - cannot be called anyway
if (func->tokenDef && func->tokenDef->next() && Token::Match(func->tokenDef->next()->link(), ") const| = delete"))
continue;
// use definition for check so we don't have to deal with qualification
if (!(Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className)) {
// make sure we really have a copy assignment operator

View File

@ -556,6 +556,14 @@ private:
"};");
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
checkOpertorEq("class A\n"
"{\n"
"public:\n"
" void goo() {}"
" void operator=(const A&)=delete;\n"
"};");
ASSERT_EQUALS("", errout.str());
checkOpertorEq("class A\n"
"{\n"
"private:\n"
@ -563,6 +571,13 @@ private:
"};");
ASSERT_EQUALS("", errout.str());
checkOpertorEq("class A\n"
"{\n"
"private:\n"
" void operator=(const A&)=delete;\n"
"};");
ASSERT_EQUALS("", errout.str());
checkOpertorEq("class A\n"
"{\n"
" void operator=(const A&);\n"
@ -596,6 +611,12 @@ private:
" void operator=(const A&);\n"
"};");
ASSERT_EQUALS("[test.cpp:3]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
checkOpertorEq("struct A\n"
"{\n"
" void operator=(const A&)=delete;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void operatorEq2() {