Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,9 @@ static bool isDecayedPointer(const Token *tok)
return false;
if (!tok->astParent())
return false;
// Subscript 'arr[i]': the element is accessed, the array itself is not used as a pointer
if (Token::simpleMatch(tok->astParent(), "[") && astIsLHS(tok))
return false;
if (Token::simpleMatch(tok->astParent(), "=") && astIsRHS(tok))
return true;
if (astIsPointer(tok->astParent()) && !Token::simpleMatch(tok->astParent(), "return"))
Expand Down
9 changes: 9 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,15 @@ class TestValueFlow : public TestFixture {
ASSERT_EQUALS(false, testLifetimeOfX(code, 3, "x ["));
}

{
// array of pointers is not decayed when it is subscripted
const char code[] = "const char* x[10];\n"
"void f() {\n"
" x[0] = \"a\";\n"
"}\n";
ASSERT_EQUALS(false, testLifetimeOfX(code, 3, "x ["));
}

{
const char code[] = "void f() {\n"
" std::vector<int> v;\n"
Expand Down
Loading