Fixed #1516 (C++Builder properties mistaken for uninitialized variables)

This commit is contained in:
Daniel Marjamäki 2010-03-28 10:58:03 +02:00
parent c7867af3c5
commit 16124ce646
2 changed files with 29 additions and 14 deletions

View File

@ -64,20 +64,16 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
if (indentlevel != 1)
continue;
// Borland C++: Skip all variables in the __published section.
// These are automaticly initialized.
if (tok->str() == "__published:")
{
priv = false;
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:"))
tok = tok->link();
if (Token::Match(tok->next(), "private:|protected:|public:"))
break;
}
if (tok)
@ -108,6 +104,10 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
if (next->str() == "static")
continue;
// Borland C++: Ignore properties..
if (next->str() == "__property")
continue;
// Type definitions shall be ignored..
if (next->str() == "typedef")
continue;

View File

@ -61,7 +61,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(uninitVarPublished); // Borland C++: Variables in the published section are auto-initialized
TEST_CASE(uninitProperty); // Borland C++: No FP for properties
TEST_CASE(uninitOperator); // No FP about uninitialized 'operator[]'
TEST_CASE(uninitFunction1); // No FP when initialized in function
TEST_CASE(uninitFunction2); // No FP when initialized in function
@ -1407,7 +1408,7 @@ private:
ASSERT_EQUALS("[fred.h:6]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
}
// Borland C++: No FP for published pointers - they are automaticly initialized
void uninitVarPublished()
{
checkUninitVar("class Fred\n"
@ -1420,6 +1421,20 @@ private:
ASSERT_EQUALS("", errout.str());
}
// Borland C++: No FP for properties
void uninitProperty()
{
checkUninitVar("class Fred\n"
"{\n"
"private:\n"
" int * i_;\n"
"public:\n"
" Fred() { i_ = 0; }\n"
" __property int * i = {read=i_, write=i_};\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void uninitOperator()
{
checkUninitVar("class Fred\n"