Fixed #1730 (False negative in 'variable not initialized in ctor')
This commit is contained in:
parent
ad9d1375aa
commit
9c4bbd4c65
|
@ -367,8 +367,16 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
|||
else // there is a called member function, but it is not defined where we can find it, so we assume it initializes everything
|
||||
{
|
||||
// check if the function is part of this class..
|
||||
const Token *tok = Token::findmatch(_tokenizer->tokens(), ((isStruct ? std::string("struct ") : std::string("class ")) + classname + " {").c_str());
|
||||
for (tok = tok ? tok->tokAt(3) : 0; tok; tok = tok->next())
|
||||
const Token *tok = Token::findmatch(_tokenizer->tokens(), ((isStruct ? std::string("struct ") : std::string("class ")) + classname + " {|:").c_str());
|
||||
bool derived = false;
|
||||
while (tok && tok->str() != "{")
|
||||
{
|
||||
if (tok->str() == ":")
|
||||
derived = true;
|
||||
tok = tok->next();
|
||||
}
|
||||
|
||||
for (tok = tok ? tok->next() : 0; tok; tok = tok->next())
|
||||
{
|
||||
if (tok->str() == "{")
|
||||
{
|
||||
|
@ -382,13 +390,15 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
|||
}
|
||||
else if (tok->str() == ftok->str() || tok->str() == "friend")
|
||||
{
|
||||
tok = 0;
|
||||
break;
|
||||
if (tok->next()->str() == "(" || tok->str() == "friend")
|
||||
{
|
||||
tok = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bail out..
|
||||
if (!tok)
|
||||
if (!tok || derived)
|
||||
{
|
||||
for (Var *var = varlist; var; var = var->next)
|
||||
var->init = true;
|
||||
|
|
|
@ -52,6 +52,7 @@ private:
|
|||
TEST_CASE(uninitVar6);
|
||||
TEST_CASE(uninitVar7);
|
||||
TEST_CASE(uninitVar8);
|
||||
TEST_CASE(uninitVar9); // ticket #1730
|
||||
TEST_CASE(uninitVarEnum);
|
||||
TEST_CASE(uninitVarStream);
|
||||
TEST_CASE(uninitVarTypedef);
|
||||
|
@ -1583,6 +1584,21 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:8]: (style) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitVar9() // ticket #1730
|
||||
{
|
||||
checkUninitVar("class Prefs {\n"
|
||||
"private:\n"
|
||||
" int xasd;\n"
|
||||
"public:\n"
|
||||
" Prefs(wxSize size);\n"
|
||||
"};\n"
|
||||
"Prefs::Prefs(wxSize size)\n"
|
||||
"{\n"
|
||||
" SetMinSize( wxSize( 48,48 ) );\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Prefs::xasd'\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarArray1()
|
||||
{
|
||||
checkUninitVar("class John\n"
|
||||
|
|
Loading…
Reference in New Issue