Fix SymbolDatabase for 'extern const char ( * x [ 256 ] ) ;'

This commit is contained in:
Daniel Marjamäki 2020-10-02 08:25:43 +02:00
parent 7bf6883d1a
commit 1251d35ba4
2 changed files with 13 additions and 0 deletions

View File

@ -4113,6 +4113,12 @@ static const Token* skipPointers(const Token* tok)
tok = tok->tokAt(2);
}
if (Token::simpleMatch(tok, "( *") && Token::simpleMatch(tok->link()->previous(), "] ) ;")) {
const Token *tok2 = skipPointers(tok->next());
if (Token::Match(tok2, "%name% [") && Token::simpleMatch(tok2->linkAt(1), "] ) ;"))
return tok2;
}
return tok;
}

View File

@ -324,6 +324,7 @@ private:
TEST_CASE(symboldatabase84);
TEST_CASE(symboldatabase85);
TEST_CASE(symboldatabase86);
TEST_CASE(symboldatabase87); // #9922 'extern const char ( * x [ 256 ] ) ;'
TEST_CASE(createSymbolDatabaseFindAllScopes1);
@ -4739,6 +4740,12 @@ private:
ASSERT(db->scopeList.back().functionList.front().hasBody() == false);
}
void symboldatabase87() { // #9922 'extern const char ( * x [ 256 ] ) ;'
GET_SYMBOL_DB("extern const char ( * x [ 256 ] ) ;");
const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x");
ASSERT(xtok->variable());
}
void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3);