From 728ac6ae2e869c19fa0a4446a6c625ffb6f0b998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 31 Jul 2019 09:35:32 +0200 Subject: [PATCH] SymbolDatabase: Use ValueType::matchParameter for char literal parameters --- lib/symboldatabase.cpp | 21 +++++++++++---------- test/testsymboldatabase.cpp | 5 +++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 04d25f5b5..07a752994 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4234,13 +4234,14 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const } // check for a match with a char literal - else if (!funcarg->isArrayOrPointer() && Token::Match(arguments[j], "%char% ,|)")) { - if (arguments[j]->isLong() && funcarg->typeStartToken()->str() == "wchar_t") - same++; - else if (!arguments[j]->isLong() && funcarg->typeStartToken()->str() == "char") - same++; - else if (Token::Match(funcarg->typeStartToken(), "wchar_t|char|short|int|long")) - fallback1++; + else if (!funcarg->isArrayOrPointer() && Token::Match(arguments[j], "%char%")) { + ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), funcarg->valueType()); + if (res == ValueType::MatchResult::SAME) + ++same; + else if (res == ValueType::MatchResult::FALLBACK1) + ++fallback1; + else if (res == ValueType::MatchResult::FALLBACK2) + ++fallback2; } // 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)); } else if (tok->isBoolean()) { setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0U)); - } else if (tok->tokType() == Token::eChar) - setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, 0U)); - else if (tok->tokType() == Token::eString) { + } else if (tok->tokType() == Token::eChar) { + setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, tok->isLong() ? ValueType::Type::WCHAR_T : ValueType::Type::CHAR, 0U)); + } else if (tok->tokType() == Token::eString) { ValueType valuetype(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::CHAR, 1U, 1U); if (tok->isLong()) { valuetype.originalTypeName = "wchar_t"; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 8b88557aa..e964feef4 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -5225,8 +5225,9 @@ private: f = Token::findsimplematch(tokenizer.tokens(), "foo3 ( 5"); 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); + // Error: ambiguous function call + //f = Token::findsimplematch(tokenizer.tokens(), "foo3 ( 6"); + //ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 7); } void findFunction16() {