diff --git a/lib/library.cpp b/lib/library.cpp index ac29fad9a..013f891cc 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -685,6 +685,10 @@ bool Library::isNotLibraryFunction(const Token *ftok) const if (Token::Match(ftok->previous(),"::|.")) return true; + // variables are not library functions. + if (ftok->varId()) + return true; + int callargs = 0; for (const Token *tok = ftok->tokAt(2); tok && tok->str() != ")"; tok = tok->next()) { if (callargs == 0) diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index aa117623e..05fe37202 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -33,6 +33,7 @@ private: TEST_CASE(function); TEST_CASE(function_match_scope); TEST_CASE(function_match_args); + TEST_CASE(function_match_var); TEST_CASE(function_arg); TEST_CASE(function_arg_any); TEST_CASE(function_arg_valid); @@ -131,6 +132,27 @@ private: ASSERT(library.isNotLibraryFunction(tokenList.front())); } + void function_match_var() const { + const char xmldata[] = "\n" + "\n" + " \n" + " " + " \n" + ""; + tinyxml2::XMLDocument doc; + doc.Parse(xmldata, sizeof(xmldata)); + + TokenList tokenList(nullptr); + std::istringstream istr("Fred foo(123);"); // <- Variable declaration, not library function + tokenList.createTokens(istr); + tokenList.front()->next()->astOperand1(tokenList.front()); + tokenList.front()->next()->varId(1); + + Library library; + library.load(doc); + ASSERT(library.isNotLibraryFunction(tokenList.front()->next())); + } + void function_arg() const { const char xmldata[] = "\n" "\n"