Skip to content

Commit 1065438

Browse files
Fix #12128 FP uninitDerivedMemberVar with brace init (#5606)
1 parent 29001b6 commit 1065438

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/checkclass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,14 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
764764
if (initList) {
765765
if (level == 0 && Token::Match(ftok, "%name% {|(") && Token::Match(ftok->linkAt(1), "}|) ,|{")) {
766766
if (ftok->str() != func.name()) {
767-
initVar(usage, ftok->varId());
767+
if (ftok->varId())
768+
initVar(usage, ftok->varId());
769+
else { // base class constructor
770+
for (Usage& u : usage) {
771+
if (u.var->scope() != scope) // assume that all variables are initialized in base class
772+
u.init = true;
773+
}
774+
}
768775
} else { // c++11 delegate constructor
769776
const Function *member = ftok->function();
770777
// member function not found => assume it initializes all members

test/testconstructors.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,22 @@ class TestConstructors : public TestFixture {
14671467
"}\n");
14681468
ASSERT_EQUALS("", errout.str());
14691469

1470+
check("template <class T>\n" // #12128
1471+
"struct B {\n"
1472+
" T x;\n"
1473+
"};\n"
1474+
"struct D : B<double> {\n"
1475+
" D(double x) : B{ x } {}\n"
1476+
"};\n");
1477+
ASSERT_EQUALS("", errout.str());
1478+
1479+
check("struct B {\n"
1480+
" int x;\n"
1481+
"};\n"
1482+
"struct D : B {\n"
1483+
" D(int i) : B{ i } {}\n"
1484+
"};\n");
1485+
ASSERT_EQUALS("", errout.str());
14701486
}
14711487

14721488
void initvar_derived_pod_struct_with_union() {

0 commit comments

Comments
 (0)