SymbolDatabase: Use ValueType::matchParameter for char literal parameters

This commit is contained in:
Daniel Marjamäki 2019-07-31 09:35:32 +02:00
parent e629f9a90f
commit 728ac6ae2e
2 changed files with 14 additions and 12 deletions

View File

@ -4234,13 +4234,14 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
} }
// check for a match with a char literal // check for a match with a char literal
else if (!funcarg->isArrayOrPointer() && Token::Match(arguments[j], "%char% ,|)")) { else if (!funcarg->isArrayOrPointer() && Token::Match(arguments[j], "%char%")) {
if (arguments[j]->isLong() && funcarg->typeStartToken()->str() == "wchar_t") ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), funcarg->valueType());
same++; if (res == ValueType::MatchResult::SAME)
else if (!arguments[j]->isLong() && funcarg->typeStartToken()->str() == "char") ++same;
same++; else if (res == ValueType::MatchResult::FALLBACK1)
else if (Token::Match(funcarg->typeStartToken(), "wchar_t|char|short|int|long")) ++fallback1;
fallback1++; else if (res == ValueType::MatchResult::FALLBACK2)
++fallback2;
} }
// check for a match with a boolean literal // check for a match with a boolean literal
@ -5396,9 +5397,9 @@ void SymbolDatabase::setValueTypeInTokenList()
setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0U)); setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0U));
} else if (tok->isBoolean()) { } else if (tok->isBoolean()) {
setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0U)); setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0U));
} else if (tok->tokType() == Token::eChar) } else if (tok->tokType() == Token::eChar) {
setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, 0U)); setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, tok->isLong() ? ValueType::Type::WCHAR_T : ValueType::Type::CHAR, 0U));
else if (tok->tokType() == Token::eString) { } else if (tok->tokType() == Token::eString) {
ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, 1U, 1U); ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, 1U, 1U);
if (tok->isLong()) { if (tok->isLong()) {
valuetype.originalTypeName = "wchar_t"; valuetype.originalTypeName = "wchar_t";

View File

@ -5225,8 +5225,9 @@ private:
f = Token::findsimplematch(tokenizer.tokens(), "foo3 ( 5"); f = Token::findsimplematch(tokenizer.tokens(), "foo3 ( 5");
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 7); ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 7);
f = Token::findsimplematch(tokenizer.tokens(), "foo3 ( 6"); // Error: ambiguous function call
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 7); //f = Token::findsimplematch(tokenizer.tokens(), "foo3 ( 6");
//ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 7);
} }
void findFunction16() { void findFunction16() {