Fix false positive about return type when there's =delete in operator= declaration
This commit is contained in:
parent
9233e79390
commit
f926958acb
|
@ -1118,6 +1118,9 @@ void CheckClass::operatorEq()
|
||||||
|
|
||||||
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
||||||
if (func->type == Function::eOperatorEqual && func->access != Private) {
|
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
|
// use definition for check so we don't have to deal with qualification
|
||||||
if (!(Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className)) {
|
if (!(Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className)) {
|
||||||
// make sure we really have a copy assignment operator
|
// make sure we really have a copy assignment operator
|
||||||
|
|
|
@ -556,6 +556,14 @@ private:
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
|
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"
|
checkOpertorEq("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
|
@ -563,6 +571,13 @@ private:
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
checkOpertorEq("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" void operator=(const A&);\n"
|
" void operator=(const A&);\n"
|
||||||
|
@ -596,6 +611,12 @@ private:
|
||||||
" void operator=(const A&);\n"
|
" void operator=(const A&);\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) 'A::operator=' should return 'A &'.\n", errout.str());
|
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() {
|
void operatorEq2() {
|
||||||
|
|
Loading…
Reference in New Issue