ValueType::matchParameter: Improved constness matching

This commit is contained in:
Daniel Marjamäki 2019-07-30 09:19:51 +02:00
parent 914430dede
commit d5d50d9b17
2 changed files with 18 additions and 1 deletions

View File

@ -5829,7 +5829,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
return ValueType::MatchResult::UNKNOWN;
if (call->pointer != func->pointer)
return ValueType::MatchResult::UNKNOWN; // TODO
if ((call->constness | func->constness) != func->constness)
if (call->pointer > 0 && ((call->constness | func->constness) != func->constness))
return ValueType::MatchResult::UNKNOWN;
if (call->type != func->type) {
if (call->isIntegral() && func->isIntegral())

View File

@ -344,6 +344,8 @@ private:
TEST_CASE(findFunction25); // std::vector<std::shared_ptr<Fred>>
TEST_CASE(findFunction26); // #8668 - pointer parameter in function call, const pointer function argument
TEST_CASE(valueTypeMatchParameter); // ValueType::matchParameter
TEST_CASE(noexceptFunction1);
TEST_CASE(noexceptFunction2);
TEST_CASE(noexceptFunction3);
@ -5529,6 +5531,21 @@ private:
ASSERT(dostuff1->function() && dostuff1->function()->token && dostuff1->function()->token->linenr() == 1);
}
void valueTypeMatchParameter() {
ValueType vt_int;
vt_int.type = ValueType::Type::INT;
vt_int.sign = ValueType::Sign::SIGNED;
ValueType vt_const_int;
vt_const_int.type = ValueType::Type::INT;
vt_const_int.sign = ValueType::Sign::SIGNED;
vt_const_int.constness = 1;
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_int));
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_const_int, &vt_int));
ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_const_int));
}
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \
ASSERT_EQUALS(true, x != nullptr); \
if (x) ASSERT_EQUALS(true, x->isNoExcept());