From b2474fd9800b507b9ea5eaafe2b01c3a0475eaea Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Fri, 3 Jul 2009 21:22:14 +0300 Subject: [PATCH] Fix ticket #452 (Failure to detect "member var not initialized in constructor" if class inherits) http://sourceforge.net/apps/trac/cppcheck/ticket/452 --- src/checkclass.cpp | 2 +- test/testclass.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/checkclass.cpp b/src/checkclass.cpp index f9e31e1f0..50f775d4a 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -262,7 +262,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token void CheckClass::constructors() { - const char pattern_class[] = "class %var% {"; + const char pattern_class[] = "class %var% [{:]"; // Locate class const Token *tok1 = Token::findmatch(_tokenizer->tokens(), pattern_class); diff --git a/test/testclass.cpp b/test/testclass.cpp index 8dae3e568..a6d81cf27 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -192,6 +192,18 @@ private: "};\n"); ASSERT_EQUALS("[test.cpp:10]: (style) Member variable not initialized in the constructor 'Fred::_code'\n", errout.str()); + + + checkUninitVar("class A{};\n" + "\n" + "class B : public A\n" + "{\n" + "public:\n" + " B() {}\n" + "private:\n" + " float f;\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:6]: (style) Member variable not initialized in the constructor 'B::f'\n", errout.str()); } void uninitVarEnum()