From 9c31e0ce54f58c0f54aee7d62745182d3b8da9e7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 15 Nov 2021 20:36:38 +0100 Subject: [PATCH] Fix #10393 FP returnDanglingLifetime (#3562) --- lib/symboldatabase.cpp | 5 +++++ test/testautovariables.cpp | 7 +++++++ 2 files changed, 12 insertions(+) mode change 100755 => 100644 test/testautovariables.cpp diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 28b87b053..bed278f5c 100755 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6538,6 +6538,11 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to setValueType(tok, valuetype); } + else if (Token::simpleMatch(tok->previous(), "= {") && tok->tokAt(-2) && tok->tokAt(-2)->valueType()) { + ValueType vt = *tok->tokAt(-2)->valueType(); + setValueType(tok, vt); + } + // library type/function else if (tok->previous()) { if (tok->astParent() && Token::Match(tok->astOperand1(), "%name%|::")) { diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp old mode 100755 new mode 100644 index c409178fc..fa6d9d7c3 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -2474,6 +2474,13 @@ private: true); ASSERT_EQUALS("", errout.str()); + check("std::string f(std::string s) {\n" + " std::string r = { s.begin(), s.end() };\n" + " return r;\n" + "}\n", + true); + ASSERT_EQUALS("", errout.str()); + check("struct A {\n" " std::vector> mA;\n" " void f(std::unique_ptr a) {\n"