Function::returnsReference: handle type scope better

This commit is contained in:
Daniel Marjamäki 2021-04-10 14:31:50 +02:00
parent 98b4253ba6
commit eacc9e552e
2 changed files with 14 additions and 0 deletions

View File

@ -2642,6 +2642,10 @@ bool Function::returnsReference(const Function* function, bool unknown)
const Token* start = function->retDef;
while (Token::Match(start, "const|volatile"))
start = start->next();
if (Token::Match(start, ":: %name%"))
start = start->next();
while (Token::Match(start, "%name% :: %name%"))
start = start->tokAt(2);
if (start->tokAt(1) == defEnd && !start->type() && !start->isStandardType())
return unknown;
// TODO: Try to deduce the type of the expression

View File

@ -249,6 +249,8 @@ private:
TEST_CASE(functionStatic);
TEST_CASE(functionReturnsReference); // Function::returnsReference
TEST_CASE(namespaces1);
TEST_CASE(namespaces2);
TEST_CASE(namespaces3); // #3854 - unknown macro
@ -2467,6 +2469,14 @@ private:
ASSERT(func->isStatic());
}
void functionReturnsReference() {
GET_SYMBOL_DB("Fred::Reference foo();");
ASSERT_EQUALS(1, db->scopeList.back().functionList.size());
const Function &func = *db->scopeList.back().functionList.begin();
ASSERT(!Function::returnsReference(&func, false));
ASSERT(Function::returnsReference(&func, true));
}
void namespaces1() {
GET_SYMBOL_DB("namespace fred {\n"
" namespace barney {\n"