partial fix for #2867 handle derived class
This commit is contained in:
parent
7af920a70b
commit
443dd4c392
|
@ -4721,8 +4721,18 @@ void Tokenizer::removeRedundantAssignment()
|
|||
const Token * const end = tok->next()->link();
|
||||
for (Token *tok2 = tok->next(); tok2 && tok2 != end; tok2 = tok2->next())
|
||||
{
|
||||
if (Token::Match(tok2, "class|struct %type% {"))
|
||||
tok2 = tok2->tokAt(2)->link(); // skip local class or struct
|
||||
// skip local class or struct
|
||||
if (Token::Match(tok2, "class|struct %type% {|:"))
|
||||
{
|
||||
// skip to '{'
|
||||
while (tok2 && tok2->str() != "{")
|
||||
tok2 = tok2->next();
|
||||
|
||||
if (tok2)
|
||||
tok2 = tok2->link(); // skip local class or struct
|
||||
else
|
||||
return;
|
||||
}
|
||||
else if (Token::Match(tok2, "[;{}] %type% * %var% ;") && tok2->strAt(1) != "return")
|
||||
{
|
||||
tok2 = tok2->tokAt(3);
|
||||
|
|
|
@ -2222,6 +2222,16 @@ private:
|
|||
" } obj;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", errout.str());
|
||||
|
||||
checkUninitVar("Object::MemFunc() {\n"
|
||||
" class LocalClass : public copy_protected {\n"
|
||||
" public:\n"
|
||||
" LocalClass() : copy_protected(1), dataLength_(0) {}\n"
|
||||
" std::streamsize dataLength_;\n"
|
||||
" double bitsInData_;\n"
|
||||
" } obj;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarArray1()
|
||||
|
|
Loading…
Reference in New Issue