From 830f656a2538652278df1abd0c813fc5f0bb29bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 1 Mar 2015 11:46:43 +0100 Subject: [PATCH] Library: variables are not library functions (variable declarations can look like function calls) --- lib/library.cpp | 4 ++++ test/testlibrary.cpp | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) 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"