From 3f1f62e0788c8cf96284e65dcf4af0ee7ca5af8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 10 Jun 2020 21:13:53 +0200 Subject: [PATCH] Fixed #9746 (SymbolDatabase: Wrong valueType for return) --- lib/symboldatabase.cpp | 8 ++++++++ test/testsymboldatabase.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 64a7acb02..5a3a27fab 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5657,6 +5657,8 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V while (Token::Match(type, "%name%|*|&|::|(") && !Token::Match(type, "typename|template") && !type->variable() && !type->function()) { if (type->str() == "(") { + if (Token::Match(type->link(), ") const| {")) + break; if (par) break; par = true; @@ -6040,6 +6042,12 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to } } } + } else if (tok->str() == "return") { + 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)); } else if (tok->variable()) { setValueType(tok, *tok->variable()); } else if (tok->enumerator()) { diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 6ef623538..223a9d120 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6899,6 +6899,17 @@ private: // std::make_shared ASSERT_EQUALS("smart-pointer", typeOf("class C {}; x = std::make_shared();", "(")); + + // return + { + // Container + Settings sC; + Library::Container c; + c.startPattern = "C"; + c.startPattern2 = "C !!::"; + sC.library.containers["C"] = c; + ASSERT_EQUALS("container(C)", typeOf("C f(char *p) { char data[10]; return data; }", "return", "test.cpp", &sC)); + } } void variadic1() { // #7453