From d5d50d9b172418cfcaf9c567e67fbf00b817727a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 30 Jul 2019 09:19:51 +0200 Subject: [PATCH] ValueType::matchParameter: Improved constness matching --- lib/symboldatabase.cpp | 2 +- test/testsymboldatabase.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index f9eed1874..31ca39407 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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()) diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index b5a97f26a..647fa1b8f 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -344,6 +344,8 @@ private: TEST_CASE(findFunction25); // std::vector> 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());