Class checking: Fixed FP for static arrays (not initialized in constructor)

This commit is contained in:
Daniel Marjamäki 2010-06-29 12:51:18 +02:00
parent 4668359b51
commit 76133e0234
2 changed files with 25 additions and 7 deletions

View File

@ -104,19 +104,23 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
if (next->str() == "__property") if (next->str() == "__property")
continue; continue;
// Is it a static variable? // Is it const..?
bool isStatic = false; if (next->str() == "const")
if (next->str() == "static") {
next = next->next();
}
// Is it a static variable?
const bool isStatic(Token::simpleMatch(next, "static"));
if (isStatic)
{ {
isStatic = true;
next = next->next(); next = next->next();
} }
// Is it a mutable variable? // Is it a mutable variable?
bool isMutable = false; const bool isMutable(Token::simpleMatch(next, "mutable"));
if (next->str() == "mutable") if (isMutable)
{ {
isMutable = true;
next = next->next(); next = next->next();
} }

View File

@ -61,6 +61,7 @@ private:
TEST_CASE(uninitVarArray3); TEST_CASE(uninitVarArray3);
TEST_CASE(uninitVarArray4); TEST_CASE(uninitVarArray4);
TEST_CASE(uninitVarArray5); TEST_CASE(uninitVarArray5);
TEST_CASE(uninitVarArray6);
TEST_CASE(uninitVarArray2D); TEST_CASE(uninitVarArray2D);
TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor
TEST_CASE(privateCtor1); // If constructor is private.. TEST_CASE(privateCtor1); // If constructor is private..
@ -1702,6 +1703,19 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void uninitVarArray6()
{
checkUninitVar("class Foo\n"
"{\n"
"public:\n"
" Foo();\n"
" static const char STR[];\n"
"};\n"
"const char Foo::STR[] = \"abc\";\n"
"Foo::Foo() { }");
ASSERT_EQUALS("", errout.str());
}
void uninitVarArray2D() void uninitVarArray2D()
{ {
checkUninitVar("class John\n" checkUninitVar("class John\n"