From 443dd4c392e76f03592d68a608d8b66baf1937ca Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 29 Jun 2011 19:39:19 -0400 Subject: [PATCH] partial fix for #2867 handle derived class --- lib/tokenize.cpp | 14 ++++++++++++-- test/testclass.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e52111471..6a0badc5f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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); diff --git a/test/testclass.cpp b/test/testclass.cpp index 99d79262e..1b439ec37 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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()