Fix 11011: FP returnDanglingLifetime with non-const reference argument [inconclusive] (#4066)

* Fix 11011: FP returnDanglingLifetime with non-const reference argument [inconclusive]

* Format
This commit is contained in:
Paul Fultz II 2022-04-30 01:23:58 -05:00 committed by GitHub
parent 6a914dc435
commit 9fa5c4e201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -3930,7 +3930,7 @@ static void valueFlowLifetimeConstructor(Token* tok,
else else
ls.byVal(tok, tokenlist, errorLogger, settings); ls.byVal(tok, tokenlist, errorLogger, settings);
}); });
} else { } else if (!constructor->nestedIn->varlist.empty()) {
LifetimeStore::forEach(args, LifetimeStore::forEach(args,
"Passed to constructor of '" + name + "'.", "Passed to constructor of '" + name + "'.",
ValueFlow::Value::LifetimeKind::SubObject, ValueFlow::Value::LifetimeKind::SubObject,

View File

@ -3259,6 +3259,16 @@ private:
ASSERT_EQUALS( ASSERT_EQUALS(
"[test.cpp:8] -> [test.cpp:7] -> [test.cpp:8]: (error) Returning object that points to local variable 'files' that will be invalid when returning.\n", "[test.cpp:8] -> [test.cpp:7] -> [test.cpp:8]: (error) Returning object that points to local variable 'files' that will be invalid when returning.\n",
errout.str()); errout.str());
check("struct S {\n"
" explicit S(std::string& s);\n"
"}\n"
"S f() {\n"
" std::string m(\"abc\");\n"
" return S(m);\n"
"}\n",
true);
ASSERT_EQUALS("", errout.str());
} }
void danglingLifetimeAggegrateConstructor() { void danglingLifetimeAggegrateConstructor() {