Fixed #1517 (false negative: the function can be declared as const)

This commit is contained in:
Robert Reif 2010-03-23 07:34:34 +01:00 committed by Daniel Marjamäki
parent 5b1b845750
commit 637a34bfd2
2 changed files with 16 additions and 1 deletions

View File

@ -1554,8 +1554,9 @@ void CheckClass::checkConst()
// member function?
if (Token::Match(tok2, "%type% %var% (") ||
Token::Match(tok2, "%type% %type% %var% (") ||
Token::Match(tok2, "%type% :: %type% %var% (") ||
Token::Match(tok2, "const %type% &|* %var% (") ||
Token::Match(tok2, "const std :: %type% &|*| %var% (") ||
Token::Match(tok2, "const %type% :: %type% &|*| %var% (") ||
Token::Match(tok2, "%type% operator %any% ("))
{
// goto function name..

View File

@ -92,6 +92,7 @@ private:
TEST_CASE(const5); // ticket #1482
TEST_CASE(const6); // ticket #1491
TEST_CASE(const7);
TEST_CASE(const8); // ticket #1517
TEST_CASE(constoperator); // operator< can often be const
TEST_CASE(constincdec); // increment/decrement => non-const
TEST_CASE(constReturnReference);
@ -2128,6 +2129,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const8()
{
// ticket #1517
checkConst("class A {\n"
"public:\n"
" A():m_strValue(""){}\n"
" std::string strGetString() { return m_strValue; }\n"
"private:\n"
" std::string m_strValue;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::strGetString' can be const\n", errout.str());
}
// increment/decrement => not const
void constincdec()
{