Uninitialized member variables: Removed false positives when using operator= (Bug 2190376)

This commit is contained in:
Daniel Marjamäki 2008-11-01 17:00:36 +00:00
parent c284e7efad
commit 0dc9235f4f
2 changed files with 36 additions and 0 deletions

View File

@ -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?

View File

@ -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 )