Constructors: Fix checking of 'operator=' with test

This commit is contained in:
Nicolas Le Cam 2008-12-07 16:55:07 +00:00
parent acd54e24b6
commit a6b4cdb526
2 changed files with 15 additions and 1 deletions

View File

@ -429,7 +429,7 @@ void CheckClass::CheckConstructors(const TOKEN *tok1, struct VAR *varlist, const
int indentlevel = 0; int indentlevel = 0;
const TOKEN *constructor_token = FindClassFunction( tok1, className, funcname, indentlevel ); const TOKEN *constructor_token = FindClassFunction( tok1, className, funcname, indentlevel );
std::list<std::string> callstack; std::list<std::string> callstack;
ClassChecking_VarList_Initialize(tok1, constructor_token, varlist, funcname, callstack); ClassChecking_VarList_Initialize(tok1, constructor_token, varlist, className, callstack);
while ( constructor_token ) while ( constructor_token )
{ {
// Check if any variables are uninitialized // Check if any variables are uninitialized

View File

@ -64,6 +64,7 @@ private:
TEST_CASE( initvar_if ); // BUG 2190290 TEST_CASE( initvar_if ); // BUG 2190290
TEST_CASE( initvar_operator_eq1 ); // BUG 2190376 TEST_CASE( initvar_operator_eq1 ); // BUG 2190376
TEST_CASE( initvar_operator_eq2 ); // BUG 2190376 TEST_CASE( initvar_operator_eq2 ); // BUG 2190376
TEST_CASE( initvar_operator_eq3 );
TEST_CASE( initvar_same_classname ); // BUG 2208157 TEST_CASE( initvar_same_classname ); // BUG 2208157
TEST_CASE( initvar_chained_assign ); // BUG 2270433 TEST_CASE( initvar_chained_assign ); // BUG 2270433
TEST_CASE( initvar_2constructors ); // BUG 2270353 TEST_CASE( initvar_2constructors ); // BUG 2270353
@ -198,6 +199,19 @@ private:
ASSERT_EQUALS( std::string("[test.cpp:5] Uninitialized member variable 'Fred::i'\n"), errout.str() ); ASSERT_EQUALS( std::string("[test.cpp:5] Uninitialized member variable 'Fred::i'\n"), errout.str() );
} }
void initvar_operator_eq3()
{
check( "class Fred\n"
"{\n"
"public:\n"
" Fred() { Init(); }\n"
" void operator=() { Init(); }\n"
"private:\n"
" Init() { i = 0; }\n"
" int i;\n"
"};\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
void initvar_same_classname() void initvar_same_classname()
{ {