From e998cd13cab4a527139044579886c6fd6e375f99 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 30 Oct 2021 02:06:36 -0500 Subject: [PATCH] Partial fix for 10393: FP returnDanglingLifetime when constructing string from iterators [inconclusive] (#3536) --- lib/symboldatabase.cpp | 9 +++++++-- test/testautovariables.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 14c7eac53..a03c18deb 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6615,8 +6615,13 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to const Scope *functionScope = tok->scope(); while (functionScope && functionScope->isExecutable() && functionScope->type != Scope::eLambda && functionScope->type != Scope::eFunction) functionScope = functionScope->nestedIn; - if (functionScope && functionScope->type == Scope::eFunction && functionScope->function && functionScope->function->retDef) - setValueType(tok, ValueType::parseDecl(functionScope->function->retDef, mSettings)); + if (functionScope && functionScope->type == Scope::eFunction && functionScope->function && + 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()) { setValueType(tok, *tok->variable()); if (!tok->variable()->valueType() && tok->valueType()) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 2e931a8f8..285896e58 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -2456,6 +2456,12 @@ private: " return &*seq.begin();\n" "}\n"); 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()