Fixed #1323 (segfault with style in CheckClass::operatorEqRetRefThis())
This commit is contained in:
parent
19bb2940cc
commit
94c5d92b2b
|
@ -878,8 +878,8 @@ void CheckClass::operatorEqRetRefThis()
|
|||
|
||||
if (tok1 && tok1->next() && tok1->next()->str() == "{")
|
||||
{
|
||||
const Token *last = tok1->next()->link()->tokAt(-2);
|
||||
for (tok1 = tok1->tokAt(2); tok1 != last; tok1 = tok1->next())
|
||||
const Token *last = tok1->next()->link();
|
||||
for (tok1 = tok1->tokAt(2); tok1 && tok1 != last; tok1 = tok1->next())
|
||||
{
|
||||
// check for return of reference to this
|
||||
if (tok1->str() == "return")
|
||||
|
@ -930,8 +930,8 @@ void CheckClass::operatorEqRetRefThis()
|
|||
|
||||
if (tok1 && tok1->next() && tok1->next()->str() == "{")
|
||||
{
|
||||
const Token *last = tok1->next()->link()->tokAt(-2);
|
||||
for (tok1 = tok1->tokAt(2); tok1 != last; tok1 = tok1->next())
|
||||
const Token *last = tok1->next()->link();
|
||||
for (tok1 = tok1->tokAt(2); tok1 && tok1 != last; tok1 = tok1->next())
|
||||
{
|
||||
// check for return of reference to this
|
||||
if (tok1->str() == "return")
|
||||
|
|
|
@ -68,7 +68,8 @@ private:
|
|||
TEST_CASE(noConstructor4);
|
||||
|
||||
TEST_CASE(operatorEq1);
|
||||
TEST_CASE(operatorEqRetRefThis);
|
||||
TEST_CASE(operatorEqRetRefThis1);
|
||||
TEST_CASE(operatorEqRetRefThis2); // ticket #1323
|
||||
TEST_CASE(operatorEqToSelf1); // single class
|
||||
TEST_CASE(operatorEqToSelf2); // nested class
|
||||
TEST_CASE(operatorEqToSelf3); // multiple inheritance
|
||||
|
@ -175,7 +176,7 @@ private:
|
|||
checkClass.operatorEqRetRefThis();
|
||||
}
|
||||
|
||||
void operatorEqRetRefThis()
|
||||
void operatorEqRetRefThis1()
|
||||
{
|
||||
checkOpertorEqRetRefThis(
|
||||
"class A\n"
|
||||
|
@ -280,6 +281,17 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to self\n", errout.str());
|
||||
}
|
||||
|
||||
void operatorEqRetRefThis2()
|
||||
{
|
||||
// ticket # 1323
|
||||
checkOpertorEqRetRefThis(
|
||||
"class szp\n"
|
||||
"{\n"
|
||||
" szp &operator =(int *other) {};\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// Check that operator Equal checks for assignment to self
|
||||
void checkOpertorEqToSelf(const char code[])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue