Fixed #7387 (SymbolDatabase: Wrong overloaded function is picked)

This commit is contained in:
Robert Reif 2016-08-02 23:34:11 +02:00 committed by Daniel Marjamäki
parent b9030bcfcd
commit b40edca62f
2 changed files with 51 additions and 4 deletions

View File

@ -3630,6 +3630,25 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
} }
} }
// check for a match with address of a variable
else if (Token::Match(arguments[j], "& %var% ,|)")) {
const Variable * callarg = check->getVariableFromVarId(arguments[j]->next()->varId());
if (callarg) {
if (funcarg->typeEndToken()->str() == "*" &&
(funcarg->typeStartToken()->str() == "void" ||
(callarg->typeStartToken()->str() == funcarg->typeStartToken()->str() &&
callarg->typeStartToken()->isUnsigned() == funcarg->typeStartToken()->isUnsigned() &&
callarg->typeStartToken()->isLong() == funcarg->typeStartToken()->isLong()))) {
same++;
} else {
// can't match so remove this function from possible matches
matches.erase(matches.begin() + i);
erased = true;
break;
}
}
}
// check for a match with a numeric literal // check for a match with a numeric literal
else if (Token::Match(arguments[j], "%num% ,|)")) { else if (Token::Match(arguments[j], "%num% ,|)")) {
if (MathLib::isInt(arguments[j]->str())) { if (MathLib::isInt(arguments[j]->str())) {

View File

@ -296,8 +296,9 @@ private:
TEST_CASE(valuetype); TEST_CASE(valuetype);
TEST_CASE(variadic); // # 7453 TEST_CASE(variadic1); // #7453
TEST_CASE(variadic2); TEST_CASE(variadic2); // #7649
TEST_CASE(variadic3); // #7387
} }
void array() { void array() {
@ -3720,7 +3721,7 @@ private:
} }
} }
void variadic() { // #7453 void variadic1() { // #7453
{ {
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n" GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"
"int create(COther& ot, const char *c1, ...);\n" "int create(COther& ot, const char *c1, ...);\n"
@ -3751,7 +3752,7 @@ private:
} }
} }
void variadic2() { void variadic2() { // #7649
{ {
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n" GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"
"CBase* create(const wchar_t *c1, ...);\n" "CBase* create(const wchar_t *c1, ...);\n"
@ -3781,6 +3782,33 @@ private:
ASSERT_EQUALS(true, db && f && f->tokAt(2) && f->tokAt(2)->function() && f->tokAt(2)->function()->tokenDef->linenr() == 1); ASSERT_EQUALS(true, db && f && f->tokAt(2) && f->tokAt(2)->function() && f->tokAt(2)->function()->tokenDef->linenr() == 1);
} }
} }
void variadic3() { // #7387
{
GET_SYMBOL_DB("int zdcalc(const XYZ & per, short rs = 0);\n"
"double zdcalc(long& length, const XYZ * per);\n"
"long mycalc( ) {\n"
" long length;\n"
" XYZ per;\n"
" zdcalc(length, &per);\n"
"}");
const Token *f = Token::findsimplematch(tokenizer.tokens(), "zdcalc ( length");
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 2);
}
{
GET_SYMBOL_DB("double zdcalc(long& length, const XYZ * per);\n"
"int zdcalc(const XYZ & per, short rs = 0);\n"
"long mycalc( ) {\n"
" long length;\n"
" XYZ per;\n"
" zdcalc(length, &per);\n"
"}");
const Token *f = Token::findsimplematch(tokenizer.tokens(), "zdcalc ( length");
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 1);
}
}
}; };
REGISTER_TEST(TestSymbolDatabase) REGISTER_TEST(TestSymbolDatabase)