diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 8d7545efe..3a5e479ac 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5172,7 +5172,12 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const const Token *vartok = arguments[j]; while (vartok->isUnaryOp("&") || vartok->isUnaryOp("*")) 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) ++same; else if (res == ValueType::MatchResult::FALLBACK1) diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index d2a38da7c..faaf63169 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -130,6 +130,7 @@ private: TEST_CASE(initvar_alias); // #6921 TEST_CASE(initvar_templateMember); // #7205 + TEST_CASE(initvar_smartptr); // #10237 TEST_CASE(operatorEqSTL); @@ -1686,6 +1687,24 @@ private: 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& 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() { check("class Fred\n" "{\n"