From e0574feabd09cb61be708418951a8ea9e0f0a4d8 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 31 Mar 2014 21:04:01 +0200 Subject: [PATCH] Fixed problems with unknown macros for inline class methods in SymbolDatabase (#5621) --- lib/symboldatabase.cpp | 9 ++++++--- test/testsymboldatabase.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 9673288d2..dbf670dd4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -495,9 +495,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti function.hasBody = true; // find start of function '{' - while (end && end->str() != "{") + while (end && end->str() != "{" && end->str() != ";") end = end->next(); - if (!end) + if (!end || end->str() == ";") continue; scope->functionList.push_back(function); @@ -1415,9 +1415,12 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok) Scope *new_scope = &scopeList.back(); // skip to start of function - while (tok1 && ((tok1->str() != "{") || (tok1->previous() && tok1->previous()->isName() && tok1->strAt(-1) != "const" && Token::Match(tok1->link()->next(), "%type%|,|{")))) { + bool foundInitLit = false; + while (tok1 && (tok1->str() != "{" || (foundInitLit && tok1->previous()->isName()))) { if (tok1->str() == "(" || tok1->str() == "{") tok1 = tok1->link(); + if (tok1->str() == ":") + foundInitLit = true; tok1 = tok1->next(); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 09e236ecf..4e376d206 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -142,6 +142,7 @@ private: TEST_CASE(functionDeclarations); TEST_CASE(memberFunctionOfUnknownClassMacro1); TEST_CASE(memberFunctionOfUnknownClassMacro2); + TEST_CASE(memberFunctionOfUnknownClassMacro3); TEST_CASE(classWithFriend); @@ -974,6 +975,26 @@ private: } void memberFunctionOfUnknownClassMacro2() { + GET_SYMBOL_DB("class ScVbaFormatCondition { OUString getServiceImplName() SAL_OVERRIDE {} };\n" + "void getFormula1() {\n" + " sal_uInt16 nFlags = 0;\n" + " if (pDocSh && !getCellRangesForAddress(nFlags)) ;\n" + "}"); + + ASSERT(db && errout.str() == ""); + + if (db) { + const Scope *scope = db->findScopeByName("getFormula1"); + ASSERT(scope != nullptr); + ASSERT(scope && scope->nestedIn == &db->scopeList.front()); + + scope = db->findScopeByName("getServiceImplName"); + ASSERT(scope != nullptr); + ASSERT(scope && scope->nestedIn && scope->nestedIn->className == "ScVbaFormatCondition"); + } + } + + void memberFunctionOfUnknownClassMacro3() { GET_SYMBOL_DB("class ScVbaFormatCondition { OUString getServiceImplName() THROW(whatever); };\n" "void ScVbaValidation::getFormula1() {\n" " sal_uInt16 nFlags = 0;\n"