Fix #12128 FP uninitDerivedMemberVar with brace init (#5606)

This commit is contained in:
chrchr-github 2023-11-01 09:49:32 +01:00 committed by GitHub
parent 29001b651b
commit 10654386db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -764,7 +764,14 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
if (initList) {
if (level == 0 && Token::Match(ftok, "%name% {|(") && Token::Match(ftok->linkAt(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

View File

@ -1467,6 +1467,22 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("template <class T>\n" // #12128
"struct B {\n"
" T x;\n"
"};\n"
"struct D : B<double> {\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() {