Skip to content

Commit 486cc91

Browse files
committed
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.
1 parent 0037e9b commit 486cc91

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
15811581
}
15821582

15831583
// should be at a sequence point if this is a function
1584-
if (!Token::Match(tok1, ">|{|}|;|public:|protected:|private:") && tok1)
1584+
if (!Token::Match(tok1, ">|{|}|;|)|public:|protected:|private:") && tok1)
15851585
return false;
15861586
}
15871587

test/testsymboldatabase.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ class TestSymbolDatabase: public TestFixture {
331331
TEST_CASE(auto7);
332332
TEST_CASE(auto8);
333333
TEST_CASE(auto9); // #8044 (segmentation fault)
334+
335+
TEST_CASE(macroFuncionTest1);
336+
TEST_CASE(macroFuncionTest2);
334337
}
335338

336339
void array() {
@@ -5185,6 +5188,42 @@ class TestSymbolDatabase: public TestFixture {
51855188
ASSERT_EQUALS(true, db != nullptr); // not null
51865189
}
51875190

5191+
void macroFuncionTest1() {
5192+
GET_SYMBOL_DB("class MacroTest\n {"
5193+
"public:\n"
5194+
" SOME_MACRO_WITH_NO_SEMICOLON()\n"
5195+
" void Init() { }\n"
5196+
"};\n");
5197+
5198+
// 3 scopes: Global, Class, and Function
5199+
ASSERT(db && db->scopeList.size() == 3);
5200+
5201+
if (!db)
5202+
return;
5203+
5204+
const Scope *scope = db->findScopeByName("MacroTest");
5205+
ASSERT(scope && scope->functionList.size() == 1);
5206+
ASSERT(findFunctionByName("Init", scope) != NULL);
5207+
}
5208+
5209+
void macroFuncionTest2() {
5210+
GET_SYMBOL_DB("class MacroTest\n {"
5211+
"public:\n"
5212+
" SOME_MACRO_WITH_NO_SEMICOLON(1, 2, 3)\n"
5213+
" void Init() { }\n"
5214+
"};\n");
5215+
5216+
// 3 scopes: Global, Class, and Function
5217+
ASSERT(db && db->scopeList.size() == 3);
5218+
5219+
if (!db)
5220+
return;
5221+
5222+
const Scope *scope = db->findScopeByName("MacroTest");
5223+
ASSERT(scope && scope->functionList.size() == 1);
5224+
ASSERT(findFunctionByName("Init", scope) != NULL);
5225+
}
5226+
51885227
};
51895228

51905229
REGISTER_TEST(TestSymbolDatabase)

0 commit comments

Comments
 (0)