Skip to content

Commit

Permalink
Fix #12966 FN returnDanglingLifetime with std::span and array (regres…
Browse files Browse the repository at this point in the history
…sion) (#6660)
  • Loading branch information
chrchr-github authored Aug 5, 2024
1 parent de83fc7 commit 775e3d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3278,7 +3278,7 @@ static bool isDecayedPointer(const Token *tok)
return true;
if (!Token::simpleMatch(tok->astParent(), "return"))
return false;
return astIsPointer(tok->astParent());
return astIsPointer(tok->astParent()) || astIsContainerView(tok->astParent());
}

static bool isConvertedToView(const Token* tok, const Settings& settings)
Expand Down
8 changes: 8 additions & 0 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,14 @@ class TestAutoVariables : public TestFixture {
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
errout_str());

check("std::span<const int> f() {\n" // #12966
" int a[10]{};\n"
" return a;\n"
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'a' that will be invalid when returning.\n",
errout_str());
}

void danglingLifetimeUniquePtr()
Expand Down

0 comments on commit 775e3d9

Please sign in to comment.