Partial fix for 10393: FP returnDanglingLifetime when constructing string from iterators [inconclusive] (#3536)

This commit is contained in:
Paul Fultz II 2021-10-30 02:06:36 -05:00 committed by GitHub
parent e20ddd55d6
commit e998cd13ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -6615,8 +6615,13 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
const Scope *functionScope = tok->scope(); const Scope *functionScope = tok->scope();
while (functionScope && functionScope->isExecutable() && functionScope->type != Scope::eLambda && functionScope->type != Scope::eFunction) while (functionScope && functionScope->isExecutable() && functionScope->type != Scope::eLambda && functionScope->type != Scope::eFunction)
functionScope = functionScope->nestedIn; functionScope = functionScope->nestedIn;
if (functionScope && functionScope->type == Scope::eFunction && functionScope->function && functionScope->function->retDef) if (functionScope && functionScope->type == Scope::eFunction && functionScope->function &&
setValueType(tok, ValueType::parseDecl(functionScope->function->retDef, mSettings)); functionScope->function->retDef) {
ValueType vt = ValueType::parseDecl(functionScope->function->retDef, mSettings);
setValueType(tok, vt);
if (Token::simpleMatch(tok, "return {"))
setValueType(tok->next(), vt);
}
} else if (tok->variable()) { } else if (tok->variable()) {
setValueType(tok, *tok->variable()); setValueType(tok, *tok->variable());
if (!tok->variable()->valueType() && tok->valueType()) if (!tok->variable()->valueType() && tok->valueType())

View File

@ -2456,6 +2456,12 @@ private:
" return &*seq.begin();\n" " return &*seq.begin();\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("std::string f(std::string Str, int first, int last) {\n"
" return { Str.begin() + first, Str.begin() + last + 1 };\n"
"}\n",
true);
ASSERT_EQUALS("", errout.str());
} }
void danglingLifetimeContainerView() void danglingLifetimeContainerView()