Fixed #7666 (Executable scope with unknown function.)

This commit is contained in:
Robert Reif 2016-08-09 14:02:06 +02:00 committed by Daniel Marjamäki
parent 16271ffe45
commit fc1a755100
2 changed files with 53 additions and 3 deletions

View File

@ -1725,7 +1725,7 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
return !first && !second;
}
} else if (!first) { // End of argument list (first)
return second->next() && second->next()->str() == ")";
return !second->nextArgument(); // End of argument list (second)
}
} else if (second->next()->str() == "=") {
second = second->nextArgument();
@ -1767,8 +1767,8 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
break;
// variable names are different
else if ((Token::Match(first->next(), "%name% ,|)|=") &&
Token::Match(second->next(), "%name% ,|)")) &&
else if ((Token::Match(first->next(), "%name% ,|)|=|[") &&
Token::Match(second->next(), "%name% ,|)|[")) &&
(first->next()->str() != second->next()->str())) {
// skip variable names
first = first->next();

View File

@ -187,6 +187,8 @@ private:
TEST_CASE(functionArgs7); // #7652
TEST_CASE(functionArgs8); // #7653
TEST_CASE(functionArgs9); // #7657
TEST_CASE(functionArgs10);
TEST_CASE(functionArgs11);
TEST_CASE(namespaces1);
TEST_CASE(namespaces2);
@ -1755,6 +1757,54 @@ private:
}
}
void functionArgs10() {
GET_SYMBOL_DB("class Fred {\n"
"public:\n"
" Fred(Whitespace = PRESERVE_WHITESPACE);\n"
"};\n"
"Fred::Fred(Whitespace whitespace) { }");
ASSERT_EQUALS(true, db != nullptr);
if (db) {
ASSERT_EQUALS(3, db->scopeList.size());
if (db->scopeList.size() == 3) {
std::list<Scope>::const_iterator scope = db->scopeList.begin();
++scope;
ASSERT_EQUALS((unsigned int)Scope::eClass, (unsigned int)scope->type);
ASSERT_EQUALS(1, scope->functionList.size());
ASSERT(scope->functionList.begin()->functionScope != nullptr);
if (scope->functionList.begin()->functionScope) {
const Scope * functionScope = scope->functionList.begin()->functionScope;
++scope;
ASSERT(functionScope == &*scope);
}
}
}
}
void functionArgs11() {
GET_SYMBOL_DB("class Fred {\n"
"public:\n"
" void foo(char a[16]);\n"
"};\n"
"void Fred::foo(char b[16]) { }");
ASSERT_EQUALS(true, db != nullptr);
if (db) {
ASSERT_EQUALS(3, db->scopeList.size());
if (db->scopeList.size() == 3) {
std::list<Scope>::const_iterator scope = db->scopeList.begin();
++scope;
ASSERT_EQUALS((unsigned int)Scope::eClass, (unsigned int)scope->type);
ASSERT_EQUALS(1, scope->functionList.size());
ASSERT(scope->functionList.begin()->functionScope != nullptr);
if (scope->functionList.begin()->functionScope) {
const Scope * functionScope = scope->functionList.begin()->functionScope;
++scope;
ASSERT(functionScope == &*scope);
}
}
}
}
void namespaces1() {
GET_SYMBOL_DB("namespace fred {\n"
" namespace barney {\n"