From 6745d9b8ef2206e50e59775c13719decbcd73286 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 5 Jun 2009 07:34:12 +0700 Subject: [PATCH] Fixed ticket #358 (Local typedef flagged as uninitialized member) http://apps.sourceforge.net/trac/cppcheck/ticket/358 --- src/checkclass.cpp | 4 ++++ test/testclass.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/checkclass.cpp b/src/checkclass.cpp index 39a95dbbe..4a752a5bd 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -82,6 +82,10 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1, if (next->str() == "static") continue; + // Type definitions shall be ignored.. + if (next->str() == "typedef") + continue; + // Is it a variable declaration? if (Token::Match(next, "%type% %var% ;")) { diff --git a/test/testclass.cpp b/test/testclass.cpp index e12e1595d..5cede4d7b 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -45,6 +45,7 @@ private: TEST_CASE(uninitVar1); TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); + TEST_CASE(uninitVarTypedef); TEST_CASE(privateCtor1); // If constructor is private.. TEST_CASE(privateCtor2); // If constructor is private.. TEST_CASE(function); // Function is not variable @@ -225,6 +226,18 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void uninitVarTypedef() + { + checkUninitVar("class Foo\n" + "{\n" + "public:\n" + " typedef int * pointer;\n" + " Foo() : a(0) {}\n" + " pointer a;\n" + "};\n"); + + ASSERT_EQUALS("", errout.str()); + } void privateCtor1() {