From 8043930a0ff24bc8be2433c7ccb3a80356804dbb Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 6 Apr 2023 18:45:12 +0200 Subject: [PATCH] Fix FN uninitMemberVar with std::array (#4935) --- lib/checkclass.cpp | 13 +++++++++++-- test/testconstructors.cpp | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 880f18343..1f87c015f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -252,8 +252,17 @@ void CheckClass::constructors() // Check if this is a class constructor if (!var.isPointer() && !var.isPointerArray() && var.isClass() && func.type == Function::eConstructor) { // Unknown type so assume it is initialized - if (!var.type()) - continue; + if (!var.type()) { + if (var.isStlType() && var.valueType() && var.valueType()->containerTypeToken && var.getTypeName() == "std::array") { + const Token* ctt = var.valueType()->containerTypeToken; + if (!ctt->isStandardType() && + (!ctt->type() || ctt->type()->needInitialization != Type::NeedInitialization::True) && + !mSettings->library.podtype(ctt->str())) // TODO: handle complex type expression + continue; + } + else + continue; + } // Known type that doesn't need initialization or // known type that has member variables of an unknown type diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 35459d253..066e04631 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -194,6 +194,7 @@ private: TEST_CASE(uninitVarArray7); TEST_CASE(uninitVarArray8); TEST_CASE(uninitVarArray9); // ticket #6957, #6959 + TEST_CASE(uninitVarArray10); TEST_CASE(uninitVarArray2D); TEST_CASE(uninitVarArray3D); TEST_CASE(uninitVarCpp11Init1); @@ -3117,6 +3118,28 @@ private: ASSERT_EQUALS("[test.cpp:6]: (warning) Member variable 'sRAIUnitDef::List' is not initialized in the constructor.\n", errout.str()); } + void uninitVarArray10() { // #11650 + Settings s(settings); + LOAD_LIB_2(s.library, "std.cfg"); + check("struct T { int j; };\n" + "struct U { int k{}; };\n" + "struct S {\n" + " std::array a;\n" + " std::array b;\n" + " std::array c;\n" + " std::array d;\n" + " std::array e;\n" + " std::array f;\n" + "S() {}\n" + "};\n", s); + + ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'S::a' is not initialized in the constructor.\n" + "[test.cpp:10]: (warning) Member variable 'S::b' is not initialized in the constructor.\n" + "[test.cpp:10]: (warning) Member variable 'S::c' is not initialized in the constructor.\n" + "[test.cpp:10]: (warning) Member variable 'S::d' is not initialized in the constructor.\n", + errout.str()); + } + void uninitVarArray2D() { check("class John\n" "{\n"