Unitialized Members Variables: Fixed false positives when using "this"

(Bug 
2190300)
This commit is contained in:
Daniel Marjamäki 2008-11-01 06:25:42 +00:00
parent a7972ad80b
commit 644b3057ed
2 changed files with 18 additions and 1 deletions

View File

@ -209,9 +209,11 @@ static void ClassChecking_VarList_Initialize(const TOKEN *ftok, struct VAR *varl
indentlevel--;
}
if (indentlevel>=1 && Match(ftok, "[{};] %var%"))
if (indentlevel>=1 && (Match(ftok, "[{};] %var%") || Match(ftok, "[{};] this . %var%")))
{
ftok = ftok->next;
if ( Match(ftok, "this .") )
ftok = gettok(ftok, 2);
// Clearing all variables..
if (Match(ftok,"memset ( this ,"))

View File

@ -54,6 +54,8 @@ private:
TEST_CASE( simple2 );
TEST_CASE( simple3 );
TEST_CASE( simple4 );
TEST_CASE( initvar_with_this ); // BUG 2190300
}
@ -114,6 +116,19 @@ private:
ASSERT_EQUALS( std::string("[test.cpp:8] Uninitialized member variable 'Fred::i'\n"), errout.str() );
}
void initvar_with_this()
{
check( "class Fred\n"
"{\n"
"public:\n"
" Fred()\n"
" { this->i = 0; }\n"
" int i;\n"
"};\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
};
REGISTER_TEST( TestConstructors )