From f40317783ee323df4f1dfed7367b2f9234436432 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 31 Jan 2024 22:13:28 +0100 Subject: [PATCH] Fix #12395 debug: SymbolDatabase couldn't resolve all user defined types with static member (#5929) --- lib/symboldatabase.cpp | 4 +++- test/testsymboldatabase.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 68500acdfa3..3f54a849a99 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -937,6 +937,8 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization() bool unknown = false; for (const Variable& var: scope.varlist) { + if (var.isStatic()) + continue; if (var.isClass() && !var.isReference()) { if (var.type()) { // does this type need initialization? @@ -947,7 +949,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization() unknown = true; } } - } else if (!var.hasDefault() && !var.isStatic()) { + } else if (!var.hasDefault()) { needInitialization = true; break; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 3dbd434c521..cf6fb8b06da 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3034,6 +3034,14 @@ class TestSymbolDatabase : public TestFixture { "};\n"); ASSERT_EQUALS("", errout.str()); } + { + GET_SYMBOL_DB_DBG("struct S {\n" // #12395 + " static S s;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + const Variable* const s = db->getVariableFromVarId(1); + ASSERT(s->scope()->definedType->needInitialization == Type::NeedInitialization::False); + } } void tryCatch1() {