Fixed #1964 (False positive: function can be const (get this))

This commit is contained in:
Robert Reif 2010-08-20 19:47:41 +02:00 committed by Daniel Marjamäki
parent 1d0debddef
commit 7b2b844b8e
2 changed files with 16 additions and 0 deletions

View File

@ -1978,6 +1978,11 @@ bool CheckClass::checkConstFunc(const SpaceInfo *info, const Token *tok)
isconst = false;
break;
}
else if (tok1->next()->str() == "this")
{
isconst = false;
break;
}
}
// streaming: <<

View File

@ -138,6 +138,7 @@ private:
TEST_CASE(const31);
TEST_CASE(const32); // ticket #1905 - member array is assigned
TEST_CASE(const33);
TEST_CASE(const34); // ticket #1964
TEST_CASE(constoperator1); // operator< can often be const
TEST_CASE(constoperator2); // operator<<
TEST_CASE(constincdec); // increment/decrement => non-const
@ -3888,6 +3889,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const34() // ticket #1964
{
checkConst("class Bar {\n"
" void init(Foo * foo) {\n"
" foo.bar = this;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const
void constincdec()
{