From 00f6c635b8bd3559f50aa0a3907204d6908cd75e Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 22 Aug 2012 03:37:50 -0700 Subject: [PATCH] Detect functions returning a template type in SymbolDatabase Fixed comment --- lib/symboldatabase.cpp | 4 ++-- test/testsymboldatabase.cpp | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 3a1e324e9..ec611226c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -820,8 +820,8 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const // regular function? 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()->str() == "::" || tok->previous()->str() == "~" || // or a scope qualifier 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->strAt(-1) == "::" || tok->strAt(-1) == "~" || // or a scope qualifier in front of tok outerScope->isClassOrStruct()) && // or a ctor/dtor (Token::Match(tok->next()->link(), ") const| ;|{|=") || Token::Match(tok->next()->link(), ") : %var% (|::"))) { diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index f7ad6e4e7..548f37208 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -99,6 +99,7 @@ private: TEST_CASE(hasInlineClassFunctionReturningFunctionPointer); TEST_CASE(hasMissingInlineClassFunctionReturningFunctionPointer); TEST_CASE(hasClassFunctionReturningFunctionPointer); + TEST_CASE(functionDeclarationTemplate); TEST_CASE(functionDeclarations); TEST_CASE(classWithFriend); @@ -654,10 +655,28 @@ private: } } + void functionDeclarationTemplate() { + GET_SYMBOL_DB("std::map 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() { 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")); if (db) {