diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index d070bab94..9a12f4772 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3441,13 +3441,11 @@ bool isLifetimeBorrowed(const Token *tok, const Settings *settings) const Token* parent = nullptr; const ValueType* vt = tok->valueType(); std::vector 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)) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 5f3cbb728..63771346d 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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()