Detect functions returning a template type in SymbolDatabase

Fixed comment
This commit is contained in:
PKEuS 2012-08-22 03:37:50 -07:00
parent 2b5cd2effc
commit 00f6c635b8
2 changed files with 22 additions and 3 deletions

View File

@ -820,8 +820,8 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
// regular function? // regular function?
else if (Token::Match(tok, "%var% (") && tok->previous() && else if (Token::Match(tok, "%var% (") && tok->previous() &&
(tok->previous()->isName() || tok->previous()->str() == "&" || tok->previous()->str() == "*" || // Either a return type in front of tok (tok->previous()->isName() || tok->strAt(-1) == ">" || tok->strAt(-1) == "&" || tok->strAt(-1) == "*" || // Either a return type in front of tok
tok->previous()->str() == "::" || tok->previous()->str() == "~" || // or a scope qualifier in front of tok tok->strAt(-1) == "::" || tok->strAt(-1) == "~" || // or a scope qualifier in front of tok
outerScope->isClassOrStruct()) && // or a ctor/dtor outerScope->isClassOrStruct()) && // or a ctor/dtor
(Token::Match(tok->next()->link(), ") const| ;|{|=") || (Token::Match(tok->next()->link(), ") const| ;|{|=") ||
Token::Match(tok->next()->link(), ") : %var% (|::"))) { Token::Match(tok->next()->link(), ") : %var% (|::"))) {

View File

@ -99,6 +99,7 @@ private:
TEST_CASE(hasInlineClassFunctionReturningFunctionPointer); TEST_CASE(hasInlineClassFunctionReturningFunctionPointer);
TEST_CASE(hasMissingInlineClassFunctionReturningFunctionPointer); TEST_CASE(hasMissingInlineClassFunctionReturningFunctionPointer);
TEST_CASE(hasClassFunctionReturningFunctionPointer); TEST_CASE(hasClassFunctionReturningFunctionPointer);
TEST_CASE(functionDeclarationTemplate);
TEST_CASE(functionDeclarations); TEST_CASE(functionDeclarations);
TEST_CASE(classWithFriend); TEST_CASE(classWithFriend);
@ -654,10 +655,28 @@ private:
} }
} }
void functionDeclarationTemplate() {
GET_SYMBOL_DB("std::map<int, string> foo() {}")
// 2 scopes: Global and Function
ASSERT(db && db->scopeList.size() == 2 && tokenizer.getFunctionTokenByName("foo"));
if (db) {
const Scope *scope = &db->scopeList.front();
ASSERT(scope && scope->functionList.size() == 1);
const Function *foo = &scope->functionList.front();
ASSERT(foo && foo->token->str() == "foo");
ASSERT(foo && foo->hasBody);
}
}
void functionDeclarations() { void functionDeclarations() {
GET_SYMBOL_DB("void foo();\nvoid foo();\nint foo(int i);\nvoid foo() {}") GET_SYMBOL_DB("void foo();\nvoid foo();\nint foo(int i);\nvoid foo() {}")
// 3 scopes: Global, Class, and Function // 2 scopes: Global and Function
ASSERT(db && db->scopeList.size() == 2 && tokenizer.getFunctionTokenByName("foo")); ASSERT(db && db->scopeList.size() == 2 && tokenizer.getFunctionTokenByName("foo"));
if (db) { if (db) {