quick fix for #1905 (false positive: the function '...' can be declared as const (member array is assigned))

This commit is contained in:
Daniel Marjamäki 2010-08-15 08:30:21 +02:00
parent 676e0d2c70
commit e1d6320a55
2 changed files with 18 additions and 0 deletions

View File

@ -1913,6 +1913,13 @@ bool CheckClass::checkConstFunc(const SpaceInfo *info, const Token *tok)
isconst = false;
break;
}
else if (tok1->previous()->str() == "]")
{
// TODO: I assume that the assigned variable is a member variable
// don't assume it
isconst = false;
break;
}
}
// streaming: <<

View File

@ -136,6 +136,7 @@ private:
TEST_CASE(const29); // ticket #1922
TEST_CASE(const30);
TEST_CASE(const31);
TEST_CASE(const32); // ticket #1905 - member array is assigned
TEST_CASE(constoperator1); // operator< can often be const
TEST_CASE(constoperator2); // operator<<
TEST_CASE(constincdec); // increment/decrement => non-const
@ -3864,6 +3865,16 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::get' can be const\n", errout.str());
}
void const32()
{
checkConst("class Fred {\n"
"public:\n"
" std::string a[10];\n"
" void seta() { a[0] = \"\"; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const
void constincdec()
{