Fix 11024: FP returnDanglingLifetime with c_str() passed to constructor (#4072)
This commit is contained in:
parent
9f7c34272d
commit
3edb10a006
|
@ -3888,6 +3888,8 @@ static void valueFlowLifetimeConstructor(Token* tok,
|
|||
const Token* expr = tok2->astOperand2();
|
||||
if (!var)
|
||||
continue;
|
||||
if (!isLifetimeBorrowed(expr, settings))
|
||||
continue;
|
||||
const Variable* argvar = getLifetimeVariable(expr);
|
||||
if (var->isReference() || var->isRValueReference()) {
|
||||
if (argvar && argvar->isArgument() && (argvar->isReference() || argvar->isRValueReference())) {
|
||||
|
|
|
@ -3269,6 +3269,17 @@ private:
|
|||
"}\n",
|
||||
true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct S {\n"
|
||||
" std::string msg;\n"
|
||||
" explicit S(const char* m) : msg(m) {}\n"
|
||||
"};\n"
|
||||
"S f() {\n"
|
||||
" std::string s(\"abc\");\n"
|
||||
" return S(s.c_str());\n"
|
||||
"}\n",
|
||||
true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void danglingLifetimeAggegrateConstructor() {
|
||||
|
|
Loading…
Reference in New Issue