Fixed #1405 (false positive: operator = should return reference t
This commit is contained in:
parent
deb71fc566
commit
9e61e7dda8
|
@ -924,7 +924,7 @@ void CheckClass::operatorEqRetRefThis()
|
||||||
// check for return of reference to this
|
// check for return of reference to this
|
||||||
if (tok1->str() == "return")
|
if (tok1->str() == "return")
|
||||||
{
|
{
|
||||||
if (!(Token::Match(tok1->tokAt(1), "* this ;") ||
|
if (!(Token::Match(tok1->tokAt(1), "(| * this ;|=") ||
|
||||||
Token::Match(tok1->tokAt(1), "operator = (")))
|
Token::Match(tok1->tokAt(1), "operator = (")))
|
||||||
operatorEqRetRefThisError(tok);
|
operatorEqRetRefThisError(tok);
|
||||||
}
|
}
|
||||||
|
@ -976,7 +976,7 @@ void CheckClass::operatorEqRetRefThis()
|
||||||
// check for return of reference to this
|
// check for return of reference to this
|
||||||
if (tok1->str() == "return")
|
if (tok1->str() == "return")
|
||||||
{
|
{
|
||||||
if (!(Token::Match(tok1->tokAt(1), "* this ;") ||
|
if (!(Token::Match(tok1->tokAt(1), "(| * this ;|=") ||
|
||||||
Token::Match(tok1->tokAt(1), "operator = (")))
|
Token::Match(tok1->tokAt(1), "operator = (")))
|
||||||
operatorEqRetRefThisError(tok);
|
operatorEqRetRefThisError(tok);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ private:
|
||||||
TEST_CASE(operatorEq1);
|
TEST_CASE(operatorEq1);
|
||||||
TEST_CASE(operatorEqRetRefThis1);
|
TEST_CASE(operatorEqRetRefThis1);
|
||||||
TEST_CASE(operatorEqRetRefThis2); // ticket #1323
|
TEST_CASE(operatorEqRetRefThis2); // ticket #1323
|
||||||
|
TEST_CASE(operatorEqRetRefThis3); // ticket #1405
|
||||||
TEST_CASE(operatorEqToSelf1); // single class
|
TEST_CASE(operatorEqToSelf1); // single class
|
||||||
TEST_CASE(operatorEqToSelf2); // nested class
|
TEST_CASE(operatorEqToSelf2); // nested class
|
||||||
TEST_CASE(operatorEqToSelf3); // multiple inheritance
|
TEST_CASE(operatorEqToSelf3); // multiple inheritance
|
||||||
|
@ -295,6 +296,18 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void operatorEqRetRefThis3()
|
||||||
|
{
|
||||||
|
// ticket # 1405
|
||||||
|
checkOpertorEqRetRefThis(
|
||||||
|
"class A {\n"
|
||||||
|
"public:\n"
|
||||||
|
" inline A &operator =(int *other) { return (*this;) };\n"
|
||||||
|
" inline A &operator =(long *other) { return (*this = 0;) };\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
// Check that operator Equal checks for assignment to self
|
// Check that operator Equal checks for assignment to self
|
||||||
void checkOpertorEqToSelf(const char code[])
|
void checkOpertorEqToSelf(const char code[])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue