diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index a1e5b7f5e6f..4052293bd32 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 418025e33c9..8101fbfbae0 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -1467,6 +1467,22 @@ class TestConstructors : public TestFixture { "}\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() {