From 870d29944bcaf101979cfd0343c7cb665a933e6c Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 14 Jun 2013 06:32:26 +0200 Subject: [PATCH] Fixed #4852 (false positive: Member variable 'A::sz' is not initialized in the constructor) --- lib/checkclass.cpp | 4 ++-- test/testconstructors.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 786789d63..6d8ffd125 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -494,8 +494,8 @@ void CheckClass::initializeVarList(const Function &func, std::liststrAt(1), scope, usage); } - // Before a new statement there is "[{};)=]" - if (! Token::Match(ftok, "[{};()=]")) + // Before a new statement there is "[{};()=[]" + if (! Token::Match(ftok, "[{};()=[]")) continue; if (Token::simpleMatch(ftok, "( !")) diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 5211c8d4b..15387524a 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -119,6 +119,7 @@ private: TEST_CASE(uninitVar23); // ticket #3702 TEST_CASE(uninitVar24); // ticket #3190 TEST_CASE(uninitVar25); // ticket #4789 + TEST_CASE(uninitVar26); TEST_CASE(uninitVarEnum); TEST_CASE(uninitVarStream); TEST_CASE(uninitVarTypedef); @@ -1890,6 +1891,19 @@ private: "[test.cpp:42]: (warning) Member variable 'F::c' is not initialized in the constructor.\n", errout.str()); } + void uninitVar26() + { + check("class A {\n" + " int * v;\n" + " int sz;\n" + "public:\n" + " A(int s) {\n" + " v = new int [sz = s];\n" + " }\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + void uninitVarArray1() { check("class John\n" "{\n"