From 947e1635da31692913ca8c103e6db3026185fc2d Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 5 Jan 2022 13:21:31 +0100 Subject: [PATCH] Fix #9998 --- lib/symboldatabase.cpp | 2 +- test/testconstructors.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index cc8e86e677d..eca0e4278ac 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -893,7 +893,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization() if (var.isClass()) { if (var.type()) { // does this type need initialization? - if (var.type()->needInitialization == Type::NeedInitialization::True) + if (var.type()->needInitialization == Type::NeedInitialization::True && !var.hasDefault()) needInitialization = true; else if (var.type()->needInitialization == Type::NeedInitialization::Unknown) { if (!(var.valueType() && var.valueType()->type == ValueType::CONTAINER)) diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 7a5cc538cf8..c1a7a0b2b6f 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -93,6 +93,7 @@ class TestConstructors : public TestFixture { TEST_CASE(noConstructor10); // ticket #6614 TEST_CASE(noConstructor11); // ticket #3552 TEST_CASE(noConstructor12); // #8951 - member initialization + TEST_CASE(noConstructor13); // #9998 TEST_CASE(forwardDeclaration); // ticket #4290/#3190 @@ -633,6 +634,16 @@ class TestConstructors : public TestFixture { ASSERT_EQUALS("", errout.str()); } + void noConstructor13() { // #9998 + check("struct C { int v; };\n" + "struct B { C c[5] = {}; };\n" + "struct A {\n" + " A() {}\n" + " B b;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor." // ticket #3190 "SymbolDatabase: Parse of sub class constructor fails" void forwardDeclaration() {