Skip to content

Commit

Permalink
Fix #12128 FP uninitDerivedMemberVar with brace init (danmar#5606)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 1, 2023
1 parent 29001b6 commit 1065438
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/testconstructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,22 @@ class TestConstructors : public TestFixture {
"}\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() {
Expand Down

0 comments on commit 1065438

Please sign in to comment.