Skip to content

Commit 43f0094

Browse files
IOBYTEdanmar
authored andcommitted
Fixed cppcheck-opensource#5197 (SymbolDatabase: bad handling of unknown macros in function declaration)
1 parent 13cd0f4 commit 43f0094

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
486486
scope->functionList.push_back(function);
487487
}
488488

489+
// unknown macro (#5197)
490+
else if (Token::Match(end, ") %any% ;")) {
491+
tok = end->tokAt(3);
492+
493+
scope->functionList.push_back(function);
494+
}
495+
489496
// inline function
490497
else {
491498
function.isInline = true;

test/testsymboldatabase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class TestSymbolDatabase: public TestFixture {
202202
TEST_CASE(symboldatabase38); // ticket #5125 (infinite recursion)
203203
TEST_CASE(symboldatabase39); // ticket #5120 (infinite recursion)
204204
TEST_CASE(symboldatabase40); // ticket #5153
205+
TEST_CASE(symboldatabase41); // ticket #5197 (unknown macro)
205206

206207
TEST_CASE(isImplicitlyVirtual);
207208

@@ -1666,6 +1667,11 @@ class TestSymbolDatabase: public TestFixture {
16661667
ASSERT_EQUALS("", errout.str());
16671668
}
16681669

1670+
void symboldatabase41() { // ticket #5197 (unknown macro)
1671+
GET_SYMBOL_DB("struct X1 { MACRO1 f(int spd) MACRO2; };\n");
1672+
ASSERT(db && db->findScopeByName("X1") && db->findScopeByName("X1")->functionList.size() == 1 && !db->findScopeByName("X1")->functionList.front().hasBody);
1673+
}
1674+
16691675
void isImplicitlyVirtual() {
16701676
{
16711677
GET_SYMBOL_DB("class Base {\n"

0 commit comments

Comments
 (0)