From c3762903a9115b68c74ba89dd5a0866fbc7b47d6 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 9 Sep 2010 07:21:51 +0200 Subject: [PATCH] Symbol database: fixed false negative for uninitialized variable. ticket: #1895 --- lib/checkclass.cpp | 5 +---- test/testclass.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 69f603ed5..0bbfe27b9 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1020,10 +1020,7 @@ bool CheckClass::argsMatch(const Token *first, const Token *second, const std::s // skip default value assignment else if (first->next()->str() == "=") - { first = first->tokAt(2); - continue; - } // definition missing variable name else if (first->next()->str() == "," && second->next()->str() != ",") @@ -1173,7 +1170,7 @@ void CheckClass::constructors() if (classNameUsed) operatorEqVarError(it->token, info->className, var->token->str()); } - else if (it->access != Private && !var->isStatic) + else if (it->access != Private) uninitVarError(it->token, info->className, var->token->str()); } } diff --git a/test/testclass.cpp b/test/testclass.cpp index b7595da76..f6a4d1505 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -54,6 +54,7 @@ private: TEST_CASE(uninitVar8); TEST_CASE(uninitVar9); // ticket #1730 TEST_CASE(uninitVar10); // ticket #1993 + TEST_CASE(uninitVar11); TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1645,6 +1646,18 @@ private: ASSERT_EQUALS("[test.cpp:8]: (style) Member variable not initialized in the constructor 'A::var2'\n", errout.str()); } + void uninitVar11() + { + checkUninitVar("class A {\n" + "public:\n" + " A(int a = 0);\n" + "private:\n" + " int var;\n" + "};\n" + "A::A(int a) { }\n"); + ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'A::var'\n", errout.str()); + } + void uninitVarArray1() { checkUninitVar("class John\n"