From 4a4b4963ccc4029b442981595af6d5700ad6ad70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 15 Oct 2019 12:39:02 +0200 Subject: [PATCH] SymbolDatabase: Fix function lookup for '::func()' --- lib/symboldatabase.cpp | 3 +++ test/testsymboldatabase.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c2fafce20..5f431a9ba 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4547,6 +4547,9 @@ const Function* SymbolDatabase::findFunction(const Token *tok) const if (tok1->strAt(-1) == "::") { currScope = &scopeList.front(); + if (Token::Match(tok1, "%name% (")) + return currScope->findFunction(tok); + currScope = currScope->findRecordInNestedList(tok1->str()); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 33af16246..5d7e468d1 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -353,6 +353,7 @@ private: TEST_CASE(findFunction28); TEST_CASE(findFunctionContainer); TEST_CASE(findFunctionExternC); + TEST_CASE(findFunctionGlobalScope); // ::foo TEST_CASE(valueTypeMatchParameter); // ValueType::matchParameter @@ -5770,6 +5771,22 @@ private: ASSERT(a->function()); } + void findFunctionGlobalScope() { + GET_SYMBOL_DB("struct S {\n" + " void foo();\n" + " int x;\n" + "};\n" + "\n" + "int bar(int x);\n" + "\n" + "void S::foo() {\n" + " x = ::bar(x);\n" + "}"); + const Token *bar = Token::findsimplematch(tokenizer.tokens(), "bar ( x )"); + ASSERT(bar); + ASSERT(bar->function()); + } + void valueTypeMatchParameter() { ValueType vt_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0); ValueType vt_const_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0, 1);