fix #3052 (False Positive - Technically the member function 'Example::Clear' can be const.)

This commit is contained in:
Robert Reif 2011-08-28 09:21:00 -04:00
parent d643397a7e
commit 9a0d076295
2 changed files with 14 additions and 0 deletions

View File

@ -1413,6 +1413,10 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok)
{
return true;
}
else if (Token::Match(tok->tokAt(-3), "( * this )"))
{
return true;
}
else if (Token::Match(tok->tokAt(-2), "%var% . %var%"))
{
tok = tok->tokAt(-2);

View File

@ -181,6 +181,7 @@ private:
TEST_CASE(const50); // ticket #2943
TEST_CASE(const51); // ticket #3040
TEST_CASE(const52); // ticket #3049
TEST_CASE(const53); // ticket #3052
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
TEST_CASE(assigningArrayElementIsNotAConstOperation);
TEST_CASE(constoperator1); // operator< can often be const
@ -5711,6 +5712,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const53() // ticket 3052
{
checkConst("class Example {\n"
" public:\n"
" void Clear(void) { Example tmp; (*this) = tmp; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void assigningPointerToPointerIsNotAConstOperation()
{
checkConst("struct s\n"