Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,8 @@ static void valueFlowLifetimeFunction(Token *tok, const TokenList &tokenlist, Er
}
if (Function::returnsReference(f))
return;
if (astIsContainerString(tok->next()) && !astIsContainerView(tok->next()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it would be better to call ValueFlow::isLifetimeBorrowed here, which getParentValueType should get the correct valuetype with a function return.

return;
std::vector<const Token*> returns = Function::findReturns(f);
const bool inconclusive = returns.size() > 1;
bool update = false;
Expand Down
9 changes: 9 additions & 0 deletions test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2962,6 +2962,15 @@ class TestAutoVariables : public TestFixture {
" int m;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("std::string to_string(const char* p) {\n" // #14818
" return p;\n"
"}\n"
"std::string get() {\n"
" std::string s;\n"
" return to_string(s.c_str());\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void danglingLifetimeContainerView()
Expand Down
Loading