Skip to content

Commit 6338c23

Browse files
authored
Fix 10589: False positive: danglingLifetime for moved unique ptr (#3547)
1 parent f5f600b commit 6338c23

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,8 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {
25152515
{
25162516
if (value.isUninitValue())
25172517
return false;
2518+
if (value.isLifetimeValue())
2519+
return false;
25182520
return true;
25192521
}
25202522

test/testautovariables.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,15 @@ class TestAutoVariables : public TestFixture {
24652465
"}\n",
24662466
true);
24672467
ASSERT_EQUALS("", errout.str());
2468+
2469+
check("struct A {\n"
2470+
" std::vector<std::unique_ptr<int>> mA;\n"
2471+
" void f(std::unique_ptr<int> a) {\n"
2472+
" auto x = a.get();\n"
2473+
" mA.push_back(std::move(a));\n"
2474+
" }\n"
2475+
"};\n");
2476+
ASSERT_EQUALS("", errout.str());
24682477
}
24692478

24702479
void danglingLifetimeContainerView()

0 commit comments

Comments
 (0)