Skip to content

Commit 1251d35

Browse files
committed
Fix SymbolDatabase for 'extern const char ( * x [ 256 ] ) ;'
1 parent 7bf6883 commit 1251d35

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,6 +4113,12 @@ static const Token* skipPointers(const Token* tok)
41134113
tok = tok->tokAt(2);
41144114
}
41154115

4116+
if (Token::simpleMatch(tok, "( *") && Token::simpleMatch(tok->link()->previous(), "] ) ;")) {
4117+
const Token *tok2 = skipPointers(tok->next());
4118+
if (Token::Match(tok2, "%name% [") && Token::simpleMatch(tok2->linkAt(1), "] ) ;"))
4119+
return tok2;
4120+
}
4121+
41164122
return tok;
41174123
}
41184124

test/testsymboldatabase.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ class TestSymbolDatabase: public TestFixture {
324324
TEST_CASE(symboldatabase84);
325325
TEST_CASE(symboldatabase85);
326326
TEST_CASE(symboldatabase86);
327+
TEST_CASE(symboldatabase87); // #9922 'extern const char ( * x [ 256 ] ) ;'
327328

328329
TEST_CASE(createSymbolDatabaseFindAllScopes1);
329330

@@ -4739,6 +4740,12 @@ class TestSymbolDatabase: public TestFixture {
47394740
ASSERT(db->scopeList.back().functionList.front().hasBody() == false);
47404741
}
47414742

4743+
void symboldatabase87() { // #9922 'extern const char ( * x [ 256 ] ) ;'
4744+
GET_SYMBOL_DB("extern const char ( * x [ 256 ] ) ;");
4745+
const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x");
4746+
ASSERT(xtok->variable());
4747+
}
4748+
47424749
void createSymbolDatabaseFindAllScopes1() {
47434750
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
47444751
ASSERT(db->scopeList.size() == 3);

0 commit comments

Comments
 (0)