Fixed #6230 (SymbolDatabase: Wrong function() is set for token)
This commit is contained in:
parent
1f32e9eee5
commit
685fce6b91
|
@ -2923,6 +2923,8 @@ const Function* Scope::findFunction(const Token *tok) const
|
||||||
std::list<Function>::const_iterator it;
|
std::list<Function>::const_iterator it;
|
||||||
|
|
||||||
// this is a function call so try to find it based on name and arguments
|
// this is a function call so try to find it based on name and arguments
|
||||||
|
// if more than 1 function matches (it is overloaded) and we dont see which function is called, return 0
|
||||||
|
const Function *foundfunction = nullptr;
|
||||||
for (it = functionList.begin(); it != functionList.end(); ++it) {
|
for (it = functionList.begin(); it != functionList.end(); ++it) {
|
||||||
if (it->tokenDef->str() == tok->str()) {
|
if (it->tokenDef->str() == tok->str()) {
|
||||||
const Function *func = &*it;
|
const Function *func = &*it;
|
||||||
|
@ -2950,11 +2952,19 @@ const Function* Scope::findFunction(const Token *tok) const
|
||||||
|
|
||||||
// check for argument count match or default arguments
|
// check for argument count match or default arguments
|
||||||
if (args == func->argCount() ||
|
if (args == func->argCount() ||
|
||||||
(args < func->argCount() && args >= func->minArgCount()))
|
(args < func->argCount() && args >= func->minArgCount())) {
|
||||||
return func;
|
if (foundfunction == nullptr)
|
||||||
|
foundfunction = func;
|
||||||
|
else {
|
||||||
|
// Two or more functions match, don't guess which one is right
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (foundfunction)
|
||||||
|
return foundfunction;
|
||||||
|
|
||||||
// check in base classes
|
// check in base classes
|
||||||
if (isClassOrStruct() && definedType && !definedType->derivedFrom.empty()) {
|
if (isClassOrStruct() && definedType && !definedType->derivedFrom.empty()) {
|
||||||
|
|
|
@ -228,6 +228,7 @@ private:
|
||||||
TEST_CASE(findFunction2); // mismatch: parameter passed by address => reference argument
|
TEST_CASE(findFunction2); // mismatch: parameter passed by address => reference argument
|
||||||
TEST_CASE(findFunction3);
|
TEST_CASE(findFunction3);
|
||||||
TEST_CASE(findFunction4);
|
TEST_CASE(findFunction4);
|
||||||
|
TEST_CASE(findFunction5); // #6230: don't guess when there are overloaded functions
|
||||||
|
|
||||||
TEST_CASE(noexceptFunction1);
|
TEST_CASE(noexceptFunction1);
|
||||||
TEST_CASE(noexceptFunction2);
|
TEST_CASE(noexceptFunction2);
|
||||||
|
@ -2332,6 +2333,16 @@ private:
|
||||||
TODO_ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 8, false);
|
TODO_ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 8, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void findFunction5() {
|
||||||
|
GET_SYMBOL_DB("void f(A x);\n"
|
||||||
|
"void f(B x);\n"
|
||||||
|
"void caller() {\n"
|
||||||
|
" f(1);\n"
|
||||||
|
"}");
|
||||||
|
const Token *f = Token::findsimplematch(tokenizer.tokens(), "f ( 1 ) ;");
|
||||||
|
ASSERT_EQUALS(true, db && f && !f->function());
|
||||||
|
}
|
||||||
|
|
||||||
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \
|
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \
|
||||||
ASSERT_EQUALS(true, x != nullptr); \
|
ASSERT_EQUALS(true, x != nullptr); \
|
||||||
if (x) ASSERT_EQUALS(true, x->isNoExcept);
|
if (x) ASSERT_EQUALS(true, x->isNoExcept);
|
||||||
|
|
Loading…
Reference in New Issue