fix #3051 (False positive: operator= should return reference (when function takes pointer argument))
This commit is contained in:
parent
9a0d076295
commit
2d952c65e4
|
@ -827,7 +827,17 @@ void CheckClass::operatorEq()
|
|||
// use definition for check so we don't have to deal with qualification
|
||||
if (!(Token::Match(func->tokenDef->tokAt(-3), ";|}|{|public:|protected:|private: %type% &") &&
|
||||
func->tokenDef->strAt(-2) == scope->className))
|
||||
operatorEqReturnError(func->tokenDef->tokAt(-1), scope->className);
|
||||
{
|
||||
// make sure we really have a copy assignment operator
|
||||
if (Token::Match(func->tokenDef->tokAt(2), "const| %var% &"))
|
||||
{
|
||||
if (func->tokenDef->strAt(2) == "const" &&
|
||||
func->tokenDef->strAt(3) == scope->className)
|
||||
operatorEqReturnError(func->tokenDef->tokAt(-1), scope->className);
|
||||
else if (func->tokenDef->strAt(2) == scope->className)
|
||||
operatorEqReturnError(func->tokenDef->tokAt(-1), scope->className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ private:
|
|||
|
||||
TEST_CASE(operatorEq1);
|
||||
TEST_CASE(operatorEq2);
|
||||
TEST_CASE(operatorEq3); // ticket #3051
|
||||
TEST_CASE(operatorEqRetRefThis1);
|
||||
TEST_CASE(operatorEqRetRefThis2); // ticket #1323
|
||||
TEST_CASE(operatorEqRetRefThis3); // ticket #1405
|
||||
|
@ -306,6 +307,16 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'\n", errout.str());
|
||||
}
|
||||
|
||||
void operatorEq3() // ticket #3051
|
||||
{
|
||||
checkOpertorEq("class A\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" A * operator=(const A*);\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// Check that operator Equal returns reference to this
|
||||
void checkOpertorEqRetRefThis(const char code[])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue