diff --git a/CheckClass.cpp b/CheckClass.cpp index e4359eb3d..443d47d16 100644 --- a/CheckClass.cpp +++ b/CheckClass.cpp @@ -216,6 +216,14 @@ static void ClassChecking_VarList_Initialize(const TOKEN *ftok, struct VAR *varl if ( ! Match(ftok, "[{};)]") && ! Match(ftok, "else") ) continue; + // Using the operator= function to initialize all variables.. + if ( Match(ftok->next, "* this = ") ) + { + for (struct VAR *var = varlist; var; var = var->next) + var->init = true; + break; + } + if (!Match(ftok->next, "%var%") && !Match(ftok->next, "this . %var%")) continue; @@ -231,6 +239,7 @@ static void ClassChecking_VarList_Initialize(const TOKEN *ftok, struct VAR *varl { for (struct VAR *var = varlist; var; var = var->next) var->init = true; + break; } // Calling member function? diff --git a/testconstructors.cpp b/testconstructors.cpp index 9cc17a08a..0acfe5f44 100644 --- a/testconstructors.cpp +++ b/testconstructors.cpp @@ -57,6 +57,7 @@ private: TEST_CASE( initvar_with_this ); // BUG 2190300 TEST_CASE( initvar_if ); // BUG 2190290 + TEST_CASE( initvar_operator_eq ); // BUG 2190376 } @@ -147,6 +148,32 @@ private: ASSERT_EQUALS( std::string(""), errout.str() ); } + void initvar_operator_eq() + { + // Bug 2190376 - False positive, Uninitialized member variable with operator= + + check( "class Fred\n" + "{\n" + "private:\n" + " int i;\n" + "\n" + "public:\n" + " Fred()\n" + " { i = 0; }\n" + "\n" + " Fred(const Fred &fred)\n" + " { *this = fred; }\n" + "\n" + " const Fred & operator=(const Fred &fred)\n" + " { i = fred.i; return *this; }\n" + "};\n" ); + + std::string err( errout.str() ); + + ASSERT_EQUALS( std::string(""), err ); + } + + }; REGISTER_TEST( TestConstructors )