Fix #11460 unintvar false positive (#4674)

* Fix #11460 unintvar false positive

* Format
This commit is contained in:
chrchr-github 2023-01-02 17:44:52 +01:00 committed by GitHub
parent 11f1a9d1f5
commit f793b7dd35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -929,7 +929,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
if (var.isClass()) {
if (var.type()) {
// does this type need initialization?
if (var.type()->needInitialization == Type::NeedInitialization::True && !var.hasDefault())
if (var.type()->needInitialization == Type::NeedInitialization::True && !var.hasDefault() && !var.isStatic())
needInitialization = true;
else if (var.type()->needInitialization == Type::NeedInitialization::Unknown) {
if (!(var.valueType() && var.valueType()->type == ValueType::CONTAINER))

View File

@ -6249,6 +6249,18 @@ private:
" S s2 = s1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #11460
valueFlowUninit("struct B { int i; };\n"
" struct H {\n"
" void e() const;\n"
" static const B b;\n"
"};\n"
"void f() {\n"
" H h;\n"
" h.e();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void uninitvar_memberfunction() {