Fixed #9746 (SymbolDatabase: Wrong valueType for return)

This commit is contained in:
Daniel Marjamäki 2020-06-10 21:13:53 +02:00
parent 4880f30dc3
commit 3f1f62e078
2 changed files with 19 additions and 0 deletions

View File

@ -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()) {

View File

@ -6899,6 +6899,17 @@ private:
// std::make_shared
ASSERT_EQUALS("smart-pointer<C>", typeOf("class C {}; x = std::make_shared<C>();", "("));
// 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