Borland C++: Don't warn about uninitialized variables that are declared in the __published section. These are auto-initialized

This commit is contained in:
Daniel Marjamäki 2009-08-31 19:40:49 +02:00
parent 67a8a3225c
commit 03d7573208
3 changed files with 37 additions and 2 deletions

View File

@ -63,8 +63,29 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses)
if (indentlevel != 1)
continue;
if (tok->str() == "__published:")
{
for (; tok; tok = tok->next())
{
if (tok->str() == "{")
++indentlevel;
else if (tok->str() == "}")
{
if (indentlevel <= 1)
break;
--indentlevel;
}
if (indentlevel == 1 && Token::Match(tok->next(), "private:|protected:|public:"))
break;
}
if (tok)
continue;
else
break;
}
// "private:" "public:" "protected:" etc
bool b = bool((*tok->strAt(0) != ':') && strchr(tok->strAt(0), ':') != 0);
const bool b((*tok->strAt(0) != ':') && strchr(tok->strAt(0), ':') != 0);
// Search for start of statement..
if (! Token::Match(tok, "[;{}]") && ! b)

View File

@ -395,7 +395,8 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
{ "private", ":", "private:" },
{ "protected", ":", "protected:" },
{ "public", ":", "public:" }
{ "public", ":", "public:" },
{ "__published", ":", "__published:" }
};
for (unsigned ui = 0; ui < sizeof(combineWithNext) / sizeof(combineWithNext[0]); ui++)

View File

@ -55,6 +55,8 @@ private:
TEST_CASE(uninitVarHeader1); // Class is defined in header
TEST_CASE(uninitVarHeader2); // Class is defined in header
TEST_CASE(uninitVarHeader3); // Class is defined in header
TEST_CASE(uninitVarPublished); // Variables in the published section are auto-initialized
TEST_CASE(noConstructor1);
TEST_CASE(noConstructor2);
@ -563,6 +565,17 @@ private:
}
void uninitVarPublished()
{
checkUninitVar("class Fred\n"
"{\n"
"__published:\n"
" int *i;\n"
"public:\n"
" Fred() { }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}