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
4 changes: 2 additions & 2 deletions lib/vf_analyzers.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -892,7 +892,7 @@ static bool isAliasOf(const Variable * var, const Token *tok, nonneg int varid,
return false;
if (val.isLifetimeValue() && !val.isLocalLifetimeValue())
return false;
if (val.isLifetimeValue() && val.lifetimeKind != ValueFlow::Value::LifetimeKind::Address)
if (val.isLifetimeValue() && val.lifetimeKind != ValueFlow::Value::LifetimeKind::Address && val.lifetimeKind != ValueFlow::Value::LifetimeKind::SubObject)
return false;
if (!Token::Match(val.tokvalue, ".|&|*|%var%"))
return false;
Expand DownExpand Up@@ -1167,7 +1167,7 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {
}

bool isAlias(const Token* tok, bool& inconclusive) const override {
if (value.isLifetimeValue())
if (value.isLifetimeValue() && value.lifetimeKind != ValueFlow::Value::LifetimeKind::SubObject)
return false;
for (const auto& m: {
std::ref(getVars()), std::ref(getAliasedVars())
Expand Down
9 changes: 9 additions & 0 deletions test/testautovariables.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -3240,6 +3240,15 @@ class TestAutoVariables : public TestFixture {
" return s[0].p.get();\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("std::unique_ptr<int> g_p;\n"// #14958
"int* f() {\n"
" std::unique_ptr<int> tmp = std::make_unique<int>();\n"
" int* p = tmp.get();\n"
" g_p = std::move(tmp);\n"
" return p;\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}
voiddanglingLifetime() {
check("auto f() {\n"
Expand Down
Loading