diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e889be586..367f713eb 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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 diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 3fcd0518f..d74262373 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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"