Fixed #1529 (false positive: function can be const (struct member variable))

This commit is contained in:
Robert Reif 2010-03-26 18:16:33 +01:00 committed by Daniel Marjamäki
parent 258e7e292e
commit 307000b448
2 changed files with 19 additions and 0 deletions

View File

@ -123,6 +123,12 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
varname = next->strAt(1);
}
// Structure?
else if (Token::Match(next, "struct|union %type% %var% ;"))
{
varname = next->strAt(2);
}
// Pointer?
else if (Token::Match(next, "%type% * %var% ;"))
{

View File

@ -97,6 +97,7 @@ private:
TEST_CASE(const8); // ticket #1517
TEST_CASE(const9); // ticket #1515
TEST_CASE(const10); // ticket #1522
TEST_CASE(const11); // ticket #1529
TEST_CASE(constoperator); // operator< can often be const
TEST_CASE(constincdec); // increment/decrement => non-const
TEST_CASE(constReturnReference);
@ -2216,6 +2217,18 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const11()
{
// ticket #1529
checkConst("class A {\n"
"public:\n"
" void set(struct tm time) { m_time = time; }\n"
"private:\n"
" struct tm m_time;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const
void constincdec()
{