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 Token* parent = nullptr;
|
||||||
const ValueType* vt = tok->valueType();
|
const ValueType* vt = tok->valueType();
|
||||||
std::vector<ValueType> vtParents = getParentValueTypes(tok, settings, &parent);
|
std::vector<ValueType> vtParents = getParentValueTypes(tok, settings, &parent);
|
||||||
if (vt) {
|
for (const ValueType& vtParent : vtParents) {
|
||||||
for (const ValueType& vtParent : vtParents) {
|
if (isLifetimeBorrowed(vt, &vtParent))
|
||||||
if (isLifetimeBorrowed(vt, &vtParent))
|
return true;
|
||||||
return true;
|
if (isLifetimeOwned(vt, &vtParent))
|
||||||
if (isLifetimeOwned(vt, &vtParent))
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (parent) {
|
if (parent) {
|
||||||
if (isDifferentType(tok, parent))
|
if (isDifferentType(tok, parent))
|
||||||
|
|
|
@ -2573,6 +2573,12 @@ private:
|
||||||
" h = 1;\n"
|
" h = 1;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void danglingLifetimeContainerView()
|
||||||
|
|
Loading…
Reference in New Issue