Fix #9247 FP uninitMemberVar (inconclusive) (#3765)

This commit is contained in:
chrchr-github 2022-01-28 15:05:13 +01:00 committed by GitHub
parent c74eeb6bad
commit d55010c441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -5176,6 +5176,11 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
// Try to evaluate the apparently more complex expression
else if (check->isCPP()) {
const Token *vartok = arguments[j];
if (vartok->str() == ".") {
const Token* rml = nextAfterAstRightmostLeaf(vartok);
if (rml)
vartok = rml->previous();
}
while (vartok->isUnaryOp("&") || vartok->isUnaryOp("*"))
vartok = vartok->astOperand1();
const Variable* var = vartok->variable();

View File

@ -129,6 +129,7 @@ private:
TEST_CASE(initvar_nocopy1); // ticket #2474
TEST_CASE(initvar_nocopy2); // ticket #2484
TEST_CASE(initvar_nocopy3); // ticket #3611
TEST_CASE(initvar_nocopy4); // ticket #9247
TEST_CASE(initvar_with_member_function_this); // ticket #4824
TEST_CASE(initvar_destructor); // No variables need to be initialized in a destructor
@ -1598,6 +1599,22 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Member variable 'A::b' is not assigned in the copy constructor. Should it be copied?\n", errout.str());
}
void initvar_nocopy4() { // #9247
check("struct S {\n"
" S(const S & s);\n"
" void S::Set(const T& val);\n"
" void S::Set(const U& val);\n"
" T t;\n"
"};\n"
"S::S(const S& s) {\n"
" Set(s.t);\n"
"}\n"
"void S::Set(const T& val) {\n"
" t = val;\n"
"}", /*inconclusive*/ true);
ASSERT_EQUALS("", errout.str());
}
void initvar_with_member_function_this() {
check("struct Foo {\n"
" Foo(int m) { this->setMember(m); }\n"