Fix 10954: False positive: returnDanglingLifetime when using c_str() (#4006)
This commit is contained in:
parent
61b87bcc60
commit
6c82fb05a4
|
@ -3441,13 +3441,11 @@ bool isLifetimeBorrowed(const Token *tok, const Settings *settings)
|
|||
const Token* parent = nullptr;
|
||||
const ValueType* vt = tok->valueType();
|
||||
std::vector<ValueType> vtParents = getParentValueTypes(tok, settings, &parent);
|
||||
if (vt) {
|
||||
for (const ValueType& vtParent : vtParents) {
|
||||
if (isLifetimeBorrowed(vt, &vtParent))
|
||||
return true;
|
||||
if (isLifetimeOwned(vt, &vtParent))
|
||||
return false;
|
||||
}
|
||||
for (const ValueType& vtParent : vtParents) {
|
||||
if (isLifetimeBorrowed(vt, &vtParent))
|
||||
return true;
|
||||
if (isLifetimeOwned(vt, &vtParent))
|
||||
return false;
|
||||
}
|
||||
if (parent) {
|
||||
if (isDifferentType(tok, parent))
|
||||
|
|
|
@ -2573,6 +2573,12 @@ private:
|
|||
" h = 1;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("std::string f(std::string s) {\n"
|
||||
" std::string ss = (\":\" + s).c_str();\n"
|
||||
" return ss;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void danglingLifetimeContainerView()
|
||||
|
|
Loading…
Reference in New Issue