Fix #8485 FP uninitMemberVar - ctor calls function with smart pointer argument (#3835)

This commit is contained in:
chrchr-github 2022-02-16 07:02:26 +01:00 committed by GitHub
parent 52f549fa87
commit 9582032906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -5188,9 +5188,13 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
vartok = vartok->astOperand1();
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();
bool unknownDeref = false;
if (var && vartok->astParent() && vartok->astParent()->str() == "*") {
if (var->isSmartPointer() && var->valueType() && var->valueType()->smartPointerTypeToken)
var = var->valueType()->smartPointerTypeToken->variable();
else
unknownDeref = true;
}
ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), var, funcarg);
if (res == ValueType::MatchResult::SAME)
++same;
@ -5199,6 +5203,8 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
else if (res == ValueType::MatchResult::FALLBACK2)
++fallback2;
else if (res == ValueType::MatchResult::NOMATCH) {
if (unknownDeref)
continue;
// can't match so remove this function from possible matches
matches.erase(matches.begin() + i);
erased = true;

View File

@ -1726,6 +1726,15 @@ private:
" double d;\n"
"};", s);
ASSERT_EQUALS("", errout.str());
check("struct S {\n" // #8485
" explicit S(const T& rhs) { set(*rhs); }\n"
" void set(const S& v) {\n"
" d = v.d;\n"
" }\n"
" double d; \n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void operatorEqSTL() {