From 486cc91627ed3d21a1dcfd39eff6a4a3fd76ca0e Mon Sep 17 00:00:00 2001 From: Steve Browne Date: Sat, 29 Apr 2017 17:18:30 -0400 Subject: [PATCH] Added unit test and resolved issue with the symbol database not recognizing member functions if preceded by a macro that does not require a semicolon. --- lib/symboldatabase.cpp | 2 +- test/testsymboldatabase.cpp | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 1d6a286aee1..9cd36baef87 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1581,7 +1581,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const } // should be at a sequence point if this is a function - if (!Token::Match(tok1, ">|{|}|;|public:|protected:|private:") && tok1) + if (!Token::Match(tok1, ">|{|}|;|)|public:|protected:|private:") && tok1) return false; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index a6cb3d49a5e..b11450b7834 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -331,6 +331,9 @@ class TestSymbolDatabase: public TestFixture { TEST_CASE(auto7); TEST_CASE(auto8); TEST_CASE(auto9); // #8044 (segmentation fault) + + TEST_CASE(macroFuncionTest1); + TEST_CASE(macroFuncionTest2); } void array() { @@ -5185,6 +5188,42 @@ class TestSymbolDatabase: public TestFixture { ASSERT_EQUALS(true, db != nullptr); // not null } + void macroFuncionTest1() { + GET_SYMBOL_DB("class MacroTest\n {" + "public:\n" + " SOME_MACRO_WITH_NO_SEMICOLON()\n" + " void Init() { }\n" + "};\n"); + + // 3 scopes: Global, Class, and Function + ASSERT(db && db->scopeList.size() == 3); + + if (!db) + return; + + const Scope *scope = db->findScopeByName("MacroTest"); + ASSERT(scope && scope->functionList.size() == 1); + ASSERT(findFunctionByName("Init", scope) != NULL); + } + + void macroFuncionTest2() { + GET_SYMBOL_DB("class MacroTest\n {" + "public:\n" + " SOME_MACRO_WITH_NO_SEMICOLON(1, 2, 3)\n" + " void Init() { }\n" + "};\n"); + + // 3 scopes: Global, Class, and Function + ASSERT(db && db->scopeList.size() == 3); + + if (!db) + return; + + const Scope *scope = db->findScopeByName("MacroTest"); + ASSERT(scope && scope->functionList.size() == 1); + ASSERT(findFunctionByName("Init", scope) != NULL); + } + }; REGISTER_TEST(TestSymbolDatabase)