diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e40d873cc..89bd6a3ee 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -640,11 +640,12 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti tok = funcStart; // class function - if (tok->previous()->str() == "::") + if (tok->previous() && tok->previous()->str() == "::") addClassFunction(&scope, &tok, argStart); // class destructor - else if (tok->previous()->str() == "~" && + else if (tok->previous() && + tok->previous()->str() == "~" && tok->strAt(-2) == "::") addClassFunction(&scope, &tok, argStart); @@ -1100,6 +1101,17 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const } } + // UNKNOWN_MACRO(a,b) { ... } + else if (outerScope->type == Scope::eGlobal && + Token::Match(tok, "%var% (") && + tok->isUpperCaseName() && + Token::Match(tok->linkAt(1), ") {") && + (!tok->previous() || Token::Match(tok->previous(), "[;{}]"))) { + *funcStart = tok; + *argStart = tok->next(); + return true; + } + // template constructor? else if (Token::Match(tok, "%var% <") && Token::simpleMatch(tok->next()->link(), "> (")) { const Token* tok2 = tok->next()->link()->next()->link(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 05560b273..75a03e1df 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -225,6 +225,8 @@ private: TEST_CASE(garbage); + TEST_CASE(isFunction); // UNKNOWN_MACRO(a,b) { .. } + TEST_CASE(findFunction1); TEST_CASE(findFunction2); // mismatch: parameter passed by address => reference argument @@ -1986,6 +1988,19 @@ private: } } + void isFunction() { // #5602 - UNKNOWN_MACRO(a,b) { .. } + GET_SYMBOL_DB("TEST(a,b) {\n" + " std::vector messages;\n" + " foo(messages[2].size());\n" + "}"); + const Variable * const var = db ? db->getVariableFromVarId(1U) : nullptr; + ASSERT(db && + db->findScopeByName("TEST") && + var && + var->typeStartToken() && + var->typeStartToken()->str() == "std"); + } + void findFunction1() { GET_SYMBOL_DB("int foo(int x);\n" /* 1 */ "void foo();\n" /* 2 */