Fixed #8603 (SymbolDatabase: 2 scopes with same function)

This commit is contained in:
Daniel Marjamäki 2018-06-03 23:14:24 +02:00
parent df9b243227
commit 7b106c067a
2 changed files with 25 additions and 1 deletions

View File

@ -2046,7 +2046,10 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
{ {
Function* function = nullptr; Function* function = nullptr;
for (std::multimap<std::string, const Function *>::iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) { for (std::multimap<std::string, const Function *>::iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) {
if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), emptyString, 0)) { const Function *f = i->second;
if (f->hasBody())
continue;
if (Function::argsMatch(scope, f->argDef->next(), argStart->next(), emptyString, 0)) {
function = const_cast<Function *>(i->second); function = const_cast<Function *>(i->second);
break; break;
} }

View File

@ -290,6 +290,7 @@ private:
TEST_CASE(symboldatabase70); TEST_CASE(symboldatabase70);
TEST_CASE(symboldatabase71); TEST_CASE(symboldatabase71);
TEST_CASE(symboldatabase72); // #8600 TEST_CASE(symboldatabase72); // #8600
TEST_CASE(symboldatabase73); // #8603
TEST_CASE(enum1); TEST_CASE(enum1);
TEST_CASE(enum2); TEST_CASE(enum2);
@ -3941,6 +3942,26 @@ private:
ASSERT(f && f->function() && f->function()->type == Function::eCopyConstructor); ASSERT(f && f->function() && f->function()->type == Function::eCopyConstructor);
} }
void symboldatabase73() { // #8603
GET_SYMBOL_DB("namespace swizzle {\n"
" template <comp> void swizzle(tvec2<f16>) {}\n"
" template <comp x, comp y> void swizzle(tvec2<f16> v) {}\n"
"}");
ASSERT_EQUALS(4, db->scopeList.size());
ASSERT_EQUALS(2, db->functionScopes.size());
const Scope *f1 = db->functionScopes[0];
ASSERT_EQUALS(2, f1->bodyStart->linenr());
ASSERT_EQUALS(2, f1->bodyEnd->linenr());
ASSERT_EQUALS(2, f1->function->token->linenr());
const Scope *f2 = db->functionScopes[1];
ASSERT_EQUALS(3, f2->bodyStart->linenr());
ASSERT_EQUALS(3, f2->bodyEnd->linenr());
ASSERT_EQUALS(3, f2->function->token->linenr());
}
void enum1() { void enum1() {
GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;"); GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;");