Fixed #1683 (false positive: The function can be const)

This commit is contained in:
Erik Lax 2010-05-16 20:26:32 +02:00 committed by Daniel Marjamäki
parent 56d176e1ce
commit 20289b1f5b
2 changed files with 24 additions and 0 deletions

View File

@ -120,6 +120,12 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
next = next->next(); next = next->next();
} }
// Is it const..?
if (next->str() == "const")
{
next = next->next();
}
// Is it a variable declaration? // Is it a variable declaration?
if (Token::Match(next, "%type% %var% ;|:")) if (Token::Match(next, "%type% %var% ;|:"))
{ {

View File

@ -116,6 +116,7 @@ private:
TEST_CASE(const18); // ticket #1563 TEST_CASE(const18); // ticket #1563
TEST_CASE(const19); // ticket #1612 TEST_CASE(const19); // ticket #1612
TEST_CASE(const20); // ticket #1602 TEST_CASE(const20); // ticket #1602
TEST_CASE(const21); // ticket #1683
TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator1); // operator< can often be const
TEST_CASE(constoperator2); // operator<< TEST_CASE(constoperator2); // operator<<
TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constincdec); // increment/decrement => non-const
@ -3291,6 +3292,23 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::get' can be const\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::get' can be const\n", errout.str());
} }
void const21()
{
// ticket #1683
checkConst("class A\n"
"{\n"
"private:\n"
" const char * l1[10];\n"
"public:\n"
" A()\n"
" {\n"
" for (int i = 0 ; i < 10; l1[i] = NULL, i++);\n"
" }\n"
" void f1() { l1[0] = \"Hello\"; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const // increment/decrement => not const
void constincdec() void constincdec()
{ {