From 16124ce6461a40cd9d530b58ad8849b8c61cb4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 28 Mar 2010 10:58:03 +0200 Subject: [PATCH] Fixed #1516 (C++Builder properties mistaken for uninitialized variables) --- lib/checkclass.cpp | 16 ++++++++-------- test/testclass.cpp | 27 +++++++++++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2d21d915a..1462e9300 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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; diff --git a/test/testclass.cpp b/test/testclass.cpp index 08aa34f70..e8c211d25 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -35,11 +35,11 @@ private: 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(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(virtualDestructor5); // Derived class has empty destructor => no error + 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(virtualDestructor5); // Derived class has empty destructor => no error TEST_CASE(virtualDestructorProtected); TEST_CASE(virtualDestructorInherited); TEST_CASE(virtualDestructorTemplate); @@ -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"