Fix #11321 FP uninitvar for in-class member initialization (#4547)

This commit is contained in:
chrchr-github 2022-10-14 19:48:27 +02:00 committed by GitHub
parent 544ec38ca9
commit 6c24d2b865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -7424,6 +7424,8 @@ static bool needsInitialization(const Variable* var, bool cpp)
{
if (!var)
return false;
if (var->hasDefault())
return false;
if (var->isPointer())
return true;
if (var->type() && var->type()->isUnionType())

View File

@ -6127,7 +6127,7 @@ private:
" int a = ab.a;\n"
" int b = ab.b;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ab.a\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: ab.b\n", "", errout.str());
// STL class member
valueFlowUninit("struct A {\n"
@ -6227,6 +6227,17 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n",
errout.str());
valueFlowUninit("struct S {\n" // #11321
" int a = 0;\n"
" int b;\n"
"};\n"
"void f() {\n"
" S s1;\n"
" s1.b = 1;\n"
" S s2 = s1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void uninitvar_memberfunction() {