#1697 (false positive: The function can be const)

This commit is contained in:
Robert Reif 2010-05-20 06:52:59 +02:00 committed by Daniel Marjamäki
parent c31accc52a
commit 5dfbb38dc9
2 changed files with 26 additions and 8 deletions

View File

@ -145,15 +145,11 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
// Pointer?
else if (Token::Match(next, "%type% * %var% ;"))
{
varname = next->strAt(2);
}
// Pointer?
else if (Token::Match(next, "%type% %type% * %var% ;"))
{
varname = next->strAt(3);
}
else if (Token::Match(next, "%type% :: %type% * %var% ;"))
varname = next->strAt(4);
// Array?
else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator")
@ -167,9 +163,9 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
// Pointer array?
else if (Token::Match(next, "%type% * %var% ["))
{
varname = next->strAt(2);
}
else if (Token::Match(next, "%type% :: %type% * %var% ["))
varname = next->strAt(4);
// std::string..
else if (withClasses && Token::Match(next, "%type% :: %type% %var% ;"))

View File

@ -117,6 +117,7 @@ private:
TEST_CASE(const19); // ticket #1612
TEST_CASE(const20); // ticket #1602
TEST_CASE(const21); // ticket #1683
TEST_CASE(const22);
TEST_CASE(constoperator1); // operator< can often be const
TEST_CASE(constoperator2); // operator<<
TEST_CASE(constincdec); // increment/decrement => non-const
@ -3309,6 +3310,27 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const22()
{
checkConst("class A\n"
"{\n"
"private:\n"
" B::C * v1;\n"
"public:\n"
" void f1() { v1 = 0; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkConst("class A\n"
"{\n"
"private:\n"
" B::C * v1[0];\n"
"public:\n"
" void f1() { v1[0] = 0; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const
void constincdec()
{