fix #2592 (False positive: 'operator=' should return reference to self)
This commit is contained in:
parent
d20987c3da
commit
fef1142997
|
@ -872,7 +872,9 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
|
||||||
// check of *this is returned
|
// check of *this is returned
|
||||||
else if (!(Token::Match(tok->tokAt(1), "(| * this ;|=") ||
|
else if (!(Token::Match(tok->tokAt(1), "(| * this ;|=") ||
|
||||||
Token::Match(tok->tokAt(1), "(| * this +=") ||
|
Token::Match(tok->tokAt(1), "(| * this +=") ||
|
||||||
Token::simpleMatch(tok->tokAt(1), "operator= (")))
|
Token::simpleMatch(tok->tokAt(1), "operator= (") ||
|
||||||
|
(Token::Match(tok->tokAt(1), "%type% :: operator= (") &&
|
||||||
|
tok->next()->str() == scope->className)))
|
||||||
operatorEqRetRefThisError(func->token);
|
operatorEqRetRefThisError(func->token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,7 @@ private:
|
||||||
TEST_CASE(operatorEqToSelf6); // ticket # 1550
|
TEST_CASE(operatorEqToSelf6); // ticket # 1550
|
||||||
TEST_CASE(operatorEqToSelf7);
|
TEST_CASE(operatorEqToSelf7);
|
||||||
TEST_CASE(operatorEqToSelf8); // ticket #2179
|
TEST_CASE(operatorEqToSelf8); // ticket #2179
|
||||||
|
TEST_CASE(operatorEqToSelf9); // ticket #2592
|
||||||
TEST_CASE(memsetOnStruct);
|
TEST_CASE(memsetOnStruct);
|
||||||
TEST_CASE(memsetVector);
|
TEST_CASE(memsetVector);
|
||||||
TEST_CASE(memsetOnClass);
|
TEST_CASE(memsetOnClass);
|
||||||
|
@ -1299,6 +1300,26 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void operatorEqToSelf9()
|
||||||
|
{
|
||||||
|
checkOpertorEqToSelf(
|
||||||
|
"class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" Foo& operator=(Foo* pOther);\n"
|
||||||
|
" Foo& operator=(Foo& other);\n"
|
||||||
|
"};\n"
|
||||||
|
"Foo& Foo::operator=(Foo* pOther)\n"
|
||||||
|
"{\n"
|
||||||
|
" return *this;\n"
|
||||||
|
"}\n"
|
||||||
|
"Foo& Foo::operator=(Foo& other)\n"
|
||||||
|
"{\n"
|
||||||
|
" return Foo::operator=(&other);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
// Check that base classes have virtual destructors
|
// Check that base classes have virtual destructors
|
||||||
void checkVirtualDestructor(const char code[])
|
void checkVirtualDestructor(const char code[])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue