From 10654386db13b61a001b31c222d9366c3174ad2c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:49:32 +0100 Subject: [PATCH] Fix #12128 FP uninitDerivedMemberVar with brace init (#5606) --- lib/checkclass.cpp | 9 ++++++++- test/testconstructors.cpp | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index a1e5b7f5e..4052293bd 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -764,7 +764,14 @@ void CheckClass::initializeVarList(const Function &func, std::listlinkAt(1), "}|) ,|{")) { if (ftok->str() != func.name()) { - initVar(usage, ftok->varId()); + if (ftok->varId()) + initVar(usage, ftok->varId()); + else { // base class constructor + for (Usage& u : usage) { + if (u.var->scope() != scope) // assume that all variables are initialized in base class + u.init = true; + } + } } else { // c++11 delegate constructor const Function *member = ftok->function(); // member function not found => assume it initializes all members diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 418025e33..8101fbfba 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -1467,6 +1467,22 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("template \n" // #12128 + "struct B {\n" + " T x;\n" + "};\n" + "struct D : B {\n" + " D(double x) : B{ x } {}\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + + check("struct B {\n" + " int x;\n" + "};\n" + "struct D : B {\n" + " D(int i) : B{ i } {}\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void initvar_derived_pod_struct_with_union() {