Fix FN uninitMemberVar with std::array (#4935)

This commit is contained in:
chrchr-github 2023-04-06 18:45:12 +02:00 committed by GitHub
parent 1b00a0f06a
commit 8043930a0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View File

@ -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

View File

@ -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<int, 2> a;\n"
" std::array<T, 2> b;\n"
" std::array<std::size_t, 2> c;\n"
" std::array<clock_t, 2> d;\n"
" std::array<std::string, 2> e;\n"
" std::array<U, 2> 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"