Fixed #7810 (SymbolDatabase: method with redundant scope info)

This commit is contained in:
Daniel Marjamäki 2016-11-17 22:45:50 +01:00
parent 5d7a4d51ad
commit 79fc332511
2 changed files with 23 additions and 1 deletions

View File

@ -355,7 +355,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// class function?
else if (isFunction(tok, scope, &funcStart, &argStart, &declEnd)) {
if (tok->previous()->str() != "::") {
if (tok->previous()->str() != "::" || tok->strAt(-2) == scope->className) {
Function function;
// save the function definition argument start '('

View File

@ -152,6 +152,7 @@ private:
TEST_CASE(hasInlineClassFunctionReturningFunctionPointer);
TEST_CASE(hasMissingInlineClassFunctionReturningFunctionPointer);
TEST_CASE(hasClassFunctionReturningFunctionPointer);
TEST_CASE(methodWithRedundantScope);
TEST_CASE(complexFunctionArrayPtr);
TEST_CASE(pointerToMemberFunction);
TEST_CASE(hasSubClassConstructor);
@ -1120,6 +1121,27 @@ private:
}
}
void methodWithRedundantScope() {
GET_SYMBOL_DB("class Fred { void Fred::func() {} };\n")
// 3 scopes: Global, Class, and Function
ASSERT(db && db->scopeList.size() == 3);
if (db) {
const Token * const functionToken = Token::findsimplematch(tokenizer.tokens(), "func");
const Scope *scope = findFunctionScopeByToken(db, functionToken);
ASSERT(scope && scope->className == "func");
const Function *function = findFunctionByName("func", &db->scopeList.back());
ASSERT(function && function->token->str() == "func");
ASSERT(function && function->token == functionToken);
ASSERT(function && function->hasBody() && function->isInline());
}
}
void complexFunctionArrayPtr() {
GET_SYMBOL_DB("int(*p1)[10]; \n" // pointer to array 10 of int
"void(*p2)(char); \n" // pointer to function (char) returning void