Skip to content

Commit 88a9119

Browse files
authored
Fixed #11907 (False positive: uninitialized member (mutable member, const method call)) (#5384)
1 parent 204e75d commit 88a9119

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/checkclass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,14 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
988988
else if (!member->isConst() && !member->isStatic()) {
989989
assignAllVar(usage);
990990
}
991+
992+
// const method, assume it assigns all mutable members
993+
else if (member->isConst()) {
994+
for (Usage& i: usage) {
995+
if (i.var->isMutable())
996+
i.assign = true;
997+
}
998+
}
991999
}
9921000

9931001
// not member function

test/testconstructors.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class TestConstructors : public TestFixture {
116116
TEST_CASE(initvar_chained_assign); // BUG 2270433
117117
TEST_CASE(initvar_2constructors); // BUG 2270353
118118
TEST_CASE(initvar_constvar);
119+
TEST_CASE(initvar_mutablevar);
119120
TEST_CASE(initvar_staticvar);
120121
TEST_CASE(initvar_brace_init);
121122
TEST_CASE(initvar_union);
@@ -1194,6 +1195,18 @@ class TestConstructors : public TestFixture {
11941195
}
11951196

11961197

1198+
void initvar_mutablevar() {
1199+
check("class Foo {\n"
1200+
"public:\n"
1201+
" Foo() { update(); }\n"
1202+
"private:\n"
1203+
" void update() const;\n"
1204+
" mutable int x;\n"
1205+
"};");
1206+
ASSERT_EQUALS("", errout.str());
1207+
}
1208+
1209+
11971210
void initvar_staticvar() {
11981211
check("class Fred\n"
11991212
"{\n"

0 commit comments

Comments
 (0)