Library: variables are not library functions (variable declarations can look like function calls)
This commit is contained in:
parent
27388c3696
commit
830f656a25
|
@ -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)
|
||||
|
|
|
@ -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[] = "<?xml version=\"1.0\"?>\n"
|
||||
"<def>\n"
|
||||
" <function name=\"foo\">\n"
|
||||
" <arg nr=\"1\"/>"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
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[] = "<?xml version=\"1.0\"?>\n"
|
||||
"<def>\n"
|
||||
|
|
Loading…
Reference in New Issue