Fixed #7649 (SymbolDatabase: Wrong overloaded function is picked for char and wchar_t)

This commit is contained in:
Robert Reif 2016-08-02 18:54:01 +02:00 committed by Daniel Marjamäki
parent f23287544a
commit b44f448acc
2 changed files with 34 additions and 1 deletions

View File

@ -3697,7 +3697,8 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
// check for a match with a string literal
else if (Token::Match(arguments[j], "%str% ,|)") &&
funcarg->typeStartToken() != funcarg->typeEndToken() &&
Token::Match(funcarg->typeStartToken(), "char|wchar_t *")) {
((!arguments[j]->isLong() && Token::simpleMatch(funcarg->typeStartToken(), "char *")) ||
(arguments[j]->isLong() && Token::simpleMatch(funcarg->typeStartToken(), "wchar_t *")))) {
same++;
}

View File

@ -296,6 +296,7 @@ private:
TEST_CASE(valuetype);
TEST_CASE(variadic); // # 7453
TEST_CASE(variadic2);
}
void array() {
@ -3727,6 +3728,37 @@ private:
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 1);
}
}
void variadic2() {
{
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"
"CBase* create(const wchar_t *c1, ...);\n"
"int foo(COther & ot)\n"
"{\n"
" CBase* cp1 = create(\"AAAA\", 44, (char*)0);\n"
" CBase* cp2 = create(L\"AAAA\", 44, (char*)0);\n"
"}");
const Token *f = Token::findsimplematch(tokenizer.tokens(), "cp1 = create (");
ASSERT_EQUALS(true, db && f && f->tokAt(2) && f->tokAt(2)->function() && f->tokAt(2)->function()->tokenDef->linenr() == 1);
f = Token::findsimplematch(tokenizer.tokens(), "cp2 = create (");
ASSERT_EQUALS(true, db && f && f->tokAt(2) && f->tokAt(2)->function() && f->tokAt(2)->function()->tokenDef->linenr() == 2);
}
{
GET_SYMBOL_DB("CBase* create(const wchar_t *c1, ...);\n"
"CBase* create(const char *c1, ...);\n"
"int foo(COther & ot)\n"
"{\n"
" CBase* cp1 = create(\"AAAA\", 44, (char*)0);\n"
" CBase* cp2 = create(L\"AAAA\", 44, (char*)0);\n"
"}");
const Token *f = Token::findsimplematch(tokenizer.tokens(), "cp1 = create (");
ASSERT_EQUALS(true, db && f && f->tokAt(2) && f->tokAt(2)->function() && f->tokAt(2)->function()->tokenDef->linenr() == 2);
f = Token::findsimplematch(tokenizer.tokens(), "cp2 = create (");
ASSERT_EQUALS(true, db && f && f->tokAt(2) && f->tokAt(2)->function() && f->tokAt(2)->function()->tokenDef->linenr() == 1);
}
}
};
REGISTER_TEST(TestSymbolDatabase)