SymbolDatabase: Improved ValueType::matchParameter handling of containers

This commit is contained in:
Daniel Marjamäki 2019-08-02 15:59:22 +02:00
parent 26b0ea52ed
commit e66e6549ee
2 changed files with 17 additions and 0 deletions

View File

@ -5782,6 +5782,10 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
if (call->typeScope != nullptr || func->typeScope != nullptr)
return call->typeScope == func->typeScope ? ValueType::MatchResult::SAME : ValueType::MatchResult::NOMATCH;
if (call->container != nullptr || func->container != nullptr)
// TODO: verify the typename
return call->container == func->container ? ValueType::MatchResult::SAME : ValueType::MatchResult::NOMATCH;
if (func->type < ValueType::Type::VOID || func->type == ValueType::Type::UNKNOWN_INT)
return ValueType::MatchResult::UNKNOWN;

View File

@ -343,6 +343,7 @@ private:
TEST_CASE(findFunction24); // smart pointer
TEST_CASE(findFunction25); // std::vector<std::shared_ptr<Fred>>
TEST_CASE(findFunction26); // #8668 - pointer parameter in function call, const pointer function argument
TEST_CASE(findFunction27);
TEST_CASE(valueTypeMatchParameter); // ValueType::matchParameter
@ -5532,6 +5533,18 @@ private:
ASSERT(dostuff1->function() && dostuff1->function()->token && dostuff1->function()->token->linenr() == 1);
}
void findFunction27() {
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
"void f(std::vector<int> v) {\n"
" dostuff(v);\n"
"}");
(void)db;
const Token *dostuff = Token::findsimplematch(tokenizer.tokens(), "dostuff ( v ) ;");
ASSERT(dostuff->function());
ASSERT(dostuff->function() && dostuff->function()->tokenDef);
ASSERT(dostuff->function() && dostuff->function()->tokenDef && dostuff->function()->tokenDef->linenr() == 1);
}
void valueTypeMatchParameter() {
ValueType vt_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0);
ValueType vt_const_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0, 1);