Fixed #11907 (False positive: uninitialized member (mutable member, const method call)) (#5384)

This commit is contained in:
Daniel Marjamäki 2023-09-01 18:10:21 +02:00 committed by GitHub
parent 204e75dc59
commit 88a9119f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -988,6 +988,14 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
else if (!member->isConst() && !member->isStatic()) {
assignAllVar(usage);
}
// const method, assume it assigns all mutable members
else if (member->isConst()) {
for (Usage& i: usage) {
if (i.var->isMutable())
i.assign = true;
}
}
}
// not member function

View File

@ -116,6 +116,7 @@ private:
TEST_CASE(initvar_chained_assign); // BUG 2270433
TEST_CASE(initvar_2constructors); // BUG 2270353
TEST_CASE(initvar_constvar);
TEST_CASE(initvar_mutablevar);
TEST_CASE(initvar_staticvar);
TEST_CASE(initvar_brace_init);
TEST_CASE(initvar_union);
@ -1194,6 +1195,18 @@ private:
}
void initvar_mutablevar() {
check("class Foo {\n"
"public:\n"
" Foo() { update(); }\n"
"private:\n"
" void update() const;\n"
" mutable int x;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void initvar_staticvar() {
check("class Fred\n"
"{\n"