Uninitialized member variable: Added unit test that currently fails for bug 2270353 - Uninitialized variable false positive on multi constructors

This commit is contained in:
Daniel Marjamäki 2008-11-15 08:53:51 +00:00
parent 607036d4eb
commit 9034c8b27e
3 changed files with 61 additions and 26 deletions

View File

@ -1,4 +1,4 @@
/* /*
* c++check - c/c++ syntax checking * c++check - c/c++ syntax checking
* Copyright (C) 2007 Daniel Marjamäki * Copyright (C) 2007 Daniel Marjamäki
* *
@ -34,16 +34,16 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Warning on C-Style casts.. p = (kalle *)foo; // Warning on C-Style casts.. p = (kalle *)foo;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
CheckOther::CheckOther( Tokenizer *tokenizer ) CheckOther::CheckOther( Tokenizer *tokenizer )
{ {
_tokenizer = tokenizer; _tokenizer = tokenizer;
} }
CheckOther::~CheckOther() CheckOther::~CheckOther()
{ {
} }
void CheckOther::WarningOldStylePointerCast() void CheckOther::WarningOldStylePointerCast()
{ {

View File

@ -1,4 +1,4 @@
/* /*
* c++check - c/c++ syntax checking * c++check - c/c++ syntax checking
* Copyright (C) 2007 Daniel Marjamäki * Copyright (C) 2007 Daniel Marjamäki
* *
@ -22,14 +22,14 @@
#ifndef CheckOtherH #ifndef CheckOtherH
#define CheckOtherH #define CheckOtherH
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include "tokenize.h"
class CheckOther #include "tokenize.h"
{
public: class CheckOther
CheckOther( Tokenizer *tokenizer ); {
~CheckOther(); public:
CheckOther( Tokenizer *tokenizer );
~CheckOther();
// Casting // Casting
void WarningOldStylePointerCast(); void WarningOldStylePointerCast();
@ -71,12 +71,12 @@ public:
void CheckCharVariable(); void CheckCharVariable();
// Incomplete statement. A statement that only contains a constant or variable // Incomplete statement. A statement that only contains a constant or variable
void CheckIncompleteStatement(); void CheckIncompleteStatement();
private: private:
void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[] ); void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[] );
Tokenizer *_tokenizer; Tokenizer *_tokenizer;
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#endif #endif

View File

@ -1,4 +1,4 @@
/* /*
* c++check - c/c++ syntax checking * c++check - c/c++ syntax checking
* Copyright (C) 2007 Daniel Marjamäki * Copyright (C) 2007 Daniel Marjamäki
* *
@ -36,7 +36,7 @@ private:
void check( const char code[] ) void check( const char code[] )
{ {
// Tokenize.. // Tokenize..
Tokenizer tokenizer; Tokenizer tokenizer;
tokenizer.getFiles()->push_back( "test.cpp" ); tokenizer.getFiles()->push_back( "test.cpp" );
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.TokenizeCode( istr ); tokenizer.TokenizeCode( istr );
@ -64,6 +64,7 @@ private:
TEST_CASE( initvar_operator_eq ); // BUG 2190376 TEST_CASE( initvar_operator_eq ); // BUG 2190376
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
// TODO TEST_CASE( initvar_2constructors ); // BUG 2270353
} }
@ -226,6 +227,40 @@ private:
} }
void initvar_2constructors()
{
check( "class c\n"
"{\n"
" c();\n"
" c(bool b);"
"\n"
" void InitInt();\n"
"\n"
" int m_iMyInt;\n"
" int m_bMyBool;\n"
"}\n"
"\n"
"c::c()\n"
"{\n"
" m_bMyBool = false;\n"
" InitInt();"
"}\n"
"\n"
"c::c(bool b)\n"
"{\n"
" m_bMyBool = b;\n"
" InitInt();\n"
"}\n"
"\n"
"void c::InitInt()\n"
"{\n"
" m_iMyInt = 0;\n"
"}\n" );
std::string err( errout.str() );
ASSERT_EQUALS( std::string(""), err );
}
}; };
REGISTER_TEST( TestConstructors ) REGISTER_TEST( TestConstructors )