small const fix

This commit is contained in:
Robert Reif 2010-03-16 07:31:40 +01:00 committed by Daniel Marjamäki
parent 904597a8ce
commit 89c57c72c5
2 changed files with 14 additions and 1 deletions

View File

@ -1739,7 +1739,7 @@ bool CheckClass::isMemberVar(const Var *varlist, const Token *tok)
{
while (tok->previous() && !Token::Match(tok->previous(), "}|{|;|public:|protected:|private:"))
{
if (tok->previous()->str() == "this" && tok->tokAt(-2)->str() == "*")
if (Token::Match(tok->previous(), "* this"))
return true;
tok = tok->previous();

View File

@ -91,6 +91,7 @@ private:
TEST_CASE(const4);
TEST_CASE(const5); // ticket #1482
TEST_CASE(const6); // ticket #1491
TEST_CASE(const7);
TEST_CASE(constoperator); // operator< can often be const
TEST_CASE(constincdec); // increment/decrement => non-const
TEST_CASE(constReturnReference);
@ -2094,6 +2095,18 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const7()
{
checkConst("class foo {\n"
" int a;\n"
"public:\n"
" void set(int i) { a = i; }\n"
" void set(const foo & f) { *this = f; }\n"
"};\n"
"void bar() {}");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const
void constincdec()
{