From 47634a0ada999943ca07844572480ac218f8352c Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 22 Mar 2016 14:10:20 +0100 Subject: [PATCH] Fixed #7420 ((debug) Executable scope 'foo' with unknown function.) --- lib/symboldatabase.cpp | 7 +++++++ test/testsymboldatabase.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 0124fc96b..a322763b7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1621,6 +1621,13 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se // skip variable names first = first->next(); second = second->next(); + + // skip default value assignment + if (first->next()->str() == "=") { + do { + first = first->next(); + } while (!Token::Match(first->next(), ",|)")); + } } // variable with class path diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 677270bf9..165fb3af1 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -276,6 +276,8 @@ private: TEST_CASE(lambda); // ticket #5867 TEST_CASE(circularDependencies); // 6298 + TEST_CASE(executableScopeWithUnknownFunction); + TEST_CASE(valuetype); } @@ -3119,6 +3121,28 @@ private: "}"); } + void executableScopeWithUnknownFunction() { + GET_SYMBOL_DB("class Fred {\n" + " void foo(const std::string & a = "");\n" + "};\n" + "Fred::foo(const std::string & b) { }\n"); + + ASSERT(db && db->scopeList.size() == 3); + if (db && db->scopeList.size() == 3) { + std::list::const_iterator scope = db->scopeList.begin(); + ASSERT_EQUALS(Scope::eGlobal, scope->type); + ++scope; + ASSERT_EQUALS(Scope::eClass, scope->type); + const Scope * class_scope = &*scope; + ++scope; + ASSERT(class_scope->functionList.size() == 1); + if (class_scope->functionList.size() == 1) { + ASSERT(class_scope->functionList.begin()->hasBody()); + ASSERT(class_scope->functionList.begin()->functionScope == &*scope); + } + } + } + std::string typeOf(const char code[], const char pattern[], const char filename[] = "test.cpp") { Tokenizer tokenizer(&settings2, this); std::istringstream istr(code);