Fixed #1516 (C++Builder properties mistaken for uninitialized variables)
This commit is contained in:
parent
c7867af3c5
commit
16124ce646
|
@ -64,20 +64,16 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
|
||||||
if (indentlevel != 1)
|
if (indentlevel != 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Borland C++: Skip all variables in the __published section.
|
||||||
|
// These are automaticly initialized.
|
||||||
if (tok->str() == "__published:")
|
if (tok->str() == "__published:")
|
||||||
{
|
{
|
||||||
priv = false;
|
priv = false;
|
||||||
for (; tok; tok = tok->next())
|
for (; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (tok->str() == "{")
|
if (tok->str() == "{")
|
||||||
++indentlevel;
|
tok = tok->link();
|
||||||
else if (tok->str() == "}")
|
if (Token::Match(tok->next(), "private:|protected:|public:"))
|
||||||
{
|
|
||||||
if (indentlevel <= 1)
|
|
||||||
break;
|
|
||||||
--indentlevel;
|
|
||||||
}
|
|
||||||
if (indentlevel == 1 && Token::Match(tok->next(), "private:|protected:|public:"))
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (tok)
|
if (tok)
|
||||||
|
@ -108,6 +104,10 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
|
||||||
if (next->str() == "static")
|
if (next->str() == "static")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Borland C++: Ignore properties..
|
||||||
|
if (next->str() == "__property")
|
||||||
|
continue;
|
||||||
|
|
||||||
// Type definitions shall be ignored..
|
// Type definitions shall be ignored..
|
||||||
if (next->str() == "typedef")
|
if (next->str() == "typedef")
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -35,11 +35,11 @@ private:
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
TEST_CASE(virtualDestructor1); // Base class not found => no error
|
TEST_CASE(virtualDestructor1); // Base class not found => no error
|
||||||
TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor
|
TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor
|
||||||
TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual
|
TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual
|
||||||
TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error
|
TEST_CASE(virtualDestructor4); // Derived class doesn't have a destructor => no error
|
||||||
TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error
|
TEST_CASE(virtualDestructor5); // Derived class has empty destructor => no error
|
||||||
TEST_CASE(virtualDestructorProtected);
|
TEST_CASE(virtualDestructorProtected);
|
||||||
TEST_CASE(virtualDestructorInherited);
|
TEST_CASE(virtualDestructorInherited);
|
||||||
TEST_CASE(virtualDestructorTemplate);
|
TEST_CASE(virtualDestructorTemplate);
|
||||||
|
@ -61,7 +61,8 @@ private:
|
||||||
TEST_CASE(uninitVarHeader1); // Class is defined in header
|
TEST_CASE(uninitVarHeader1); // Class is defined in header
|
||||||
TEST_CASE(uninitVarHeader2); // Class is defined in header
|
TEST_CASE(uninitVarHeader2); // Class is defined in header
|
||||||
TEST_CASE(uninitVarHeader3); // 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(uninitOperator); // No FP about uninitialized 'operator[]'
|
||||||
TEST_CASE(uninitFunction1); // No FP when initialized in function
|
TEST_CASE(uninitFunction1); // No FP when initialized in function
|
||||||
TEST_CASE(uninitFunction2); // 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());
|
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()
|
void uninitVarPublished()
|
||||||
{
|
{
|
||||||
checkUninitVar("class Fred\n"
|
checkUninitVar("class Fred\n"
|
||||||
|
@ -1420,6 +1421,20 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void uninitOperator()
|
||||||
{
|
{
|
||||||
checkUninitVar("class Fred\n"
|
checkUninitVar("class Fred\n"
|
||||||
|
|
Loading…
Reference in New Issue