Skip to content

Commit

Permalink
Fix #13329 FP invalidLifetime, shadowArgument in constructor (#7027)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 25, 2024
1 parent 9304746 commit 1a52e3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5017,7 +5017,8 @@ static const Token* skipPointers(const Token* tok)
tok = tok->tokAt(2);
}

if (Token::simpleMatch(tok, "( *") && Token::simpleMatch(tok->link()->previous(), "] ) ;")) {
if (Token::simpleMatch(tok, "( *") && Token::simpleMatch(tok->link()->previous(), "] ) ;") &&
(tok->tokAt(-1)->isStandardType() || tok->tokAt(-1)->isKeyword() || tok->strAt(-1) == "*")) {
const Token *tok2 = skipPointers(tok->next());
if (Token::Match(tok2, "%name% [") && Token::simpleMatch(tok2->linkAt(1), "] ) ;"))
return tok2;
Expand Down
17 changes: 17 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(symboldatabase104);
TEST_CASE(symboldatabase105);
TEST_CASE(symboldatabase106);
TEST_CASE(symboldatabase107);

TEST_CASE(createSymbolDatabaseFindAllScopes1);
TEST_CASE(createSymbolDatabaseFindAllScopes2);
Expand Down Expand Up @@ -5656,6 +5657,22 @@ class TestSymbolDatabase : public TestFixture {
}
}

void symboldatabase107() {
{
GET_SYMBOL_DB_DBG("void g(int);\n" // #13329
"void f(int** pp) {\n"
" for (int i = 0; i < 2; i++) {\n"
" g(*pp[i]);\n"
" }\n"
"}\n");
ASSERT(db != nullptr);
ASSERT_EQUALS("", errout_str());
ASSERT_EQUALS(3, db->scopeList.size());
ASSERT_EQUALS(Scope::ScopeType::eFor, db->scopeList.back().type);
ASSERT_EQUALS(1, db->scopeList.back().varlist.size());
}
}

void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3);
Expand Down

0 comments on commit 1a52e3b

Please sign in to comment.