Fix #10237 uninitMemberVar - member initialized via function call (#3745)

This commit is contained in:
chrchr-github 2022-01-24 21:52:00 +01:00 committed by GitHub
parent 158f3d494e
commit 9d6e5c2a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -5172,7 +5172,12 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
const Token *vartok = arguments[j]; const Token *vartok = arguments[j];
while (vartok->isUnaryOp("&") || vartok->isUnaryOp("*")) while (vartok->isUnaryOp("&") || vartok->isUnaryOp("*"))
vartok = vartok->astOperand1(); vartok = vartok->astOperand1();
ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), vartok->variable(), funcarg); const Variable* var = vartok->variable();
// smart pointer deref?
if (var && vartok->astParent() && vartok->astParent()->str() == "*" &&
var->isSmartPointer() && var->valueType() && var->valueType()->smartPointerTypeToken)
var = var->valueType()->smartPointerTypeToken->variable();
ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), var, funcarg);
if (res == ValueType::MatchResult::SAME) if (res == ValueType::MatchResult::SAME)
++same; ++same;
else if (res == ValueType::MatchResult::FALLBACK1) else if (res == ValueType::MatchResult::FALLBACK1)

View File

@ -130,6 +130,7 @@ private:
TEST_CASE(initvar_alias); // #6921 TEST_CASE(initvar_alias); // #6921
TEST_CASE(initvar_templateMember); // #7205 TEST_CASE(initvar_templateMember); // #7205
TEST_CASE(initvar_smartptr); // #10237
TEST_CASE(operatorEqSTL); TEST_CASE(operatorEqSTL);
@ -1686,6 +1687,24 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void initvar_smartptr() { // #10237
Settings s;
s.libraries.emplace_back("std");
check("struct S {\n"
" explicit S(const std::shared_ptr<S>& sp) {\n"
" set(*sp);\n"
" }\n"
" double get() const {\n"
" return d;\n"
" }\n"
" void set(const S& rhs) {\n"
" d = rhs.get();\n"
" }\n"
" double d;\n"
"};", s);
ASSERT_EQUALS("", errout.str());
}
void operatorEqSTL() { void operatorEqSTL() {
check("class Fred\n" check("class Fred\n"
"{\n" "{\n"