Skip to content

Commit 7732ae4

Browse files
Merge branch 'cppcheck-opensource:main' into many.unsafe.functions.one.line
2 parents c28bcf1 + d84ae30 commit 7732ae4

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

lib/vf_analyzers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ static bool isAliasOf(const Variable * var, const Token *tok, nonneg int varid,
892892
return false;
893893
if (val.isLifetimeValue() && !val.isLocalLifetimeValue())
894894
return false;
895-
if (val.isLifetimeValue() && val.lifetimeKind != ValueFlow::Value::LifetimeKind::Address)
895+
if (val.isLifetimeValue() && val.lifetimeKind != ValueFlow::Value::LifetimeKind::Address && val.lifetimeKind != ValueFlow::Value::LifetimeKind::SubObject)
896896
return false;
897897
if (!Token::Match(val.tokvalue, ".|&|*|%var%"))
898898
return false;
@@ -1167,7 +1167,7 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {
11671167
}
11681168

11691169
bool isAlias(const Token* tok, bool& inconclusive) const override {
1170-
if (value.isLifetimeValue())
1170+
if (value.isLifetimeValue() && value.lifetimeKind != ValueFlow::Value::LifetimeKind::SubObject)
11711171
return false;
11721172
for (const auto& m: {
11731173
std::ref(getVars()), std::ref(getAliasedVars())

test/testautovariables.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,6 +3240,15 @@ class TestAutoVariables : public TestFixture {
32403240
" return s[0].p.get();\n"
32413241
"}\n");
32423242
ASSERT_EQUALS("", errout_str());
3243+
3244+
check("std::unique_ptr<int> g_p;\n" // #14958
3245+
"int* f() {\n"
3246+
" std::unique_ptr<int> tmp = std::make_unique<int>();\n"
3247+
" int* p = tmp.get();\n"
3248+
" g_p = std::move(tmp);\n"
3249+
" return p;\n"
3250+
"}\n");
3251+
ASSERT_EQUALS("", errout_str());
32433252
}
32443253
void danglingLifetime() {
32453254
check("auto f() {\n"

0 commit comments

Comments
 (0)