From 4558701c08ae3abb278e1921cc907f4eb811c453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Dec 2016 20:16:38 +0100 Subject: [PATCH] varid: don't generate varid and symboldatabase variable for function call parameter --- lib/symboldatabase.cpp | 2 +- lib/tokenize.cpp | 2 +- test/testsymboldatabase.cpp | 2 +- test/testvarid.cpp | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 7965cb9a7..d6bde9610 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3249,7 +3249,7 @@ static const Token* skipScopeIdentifiers(const Token* tok) static const Token* skipPointers(const Token* tok) { - while (Token::Match(tok, "*|&|&&") || (tok && tok->str() == "(" && Token::Match(tok->link()->next(), "(|["))) { + while (Token::Match(tok, "*|&|&&") || (Token::Match(tok, "( [*&]") && Token::Match(tok->link()->next(), "(|["))) { tok = tok->next(); if (tok->strAt(-1) == "(" && Token::Match(tok, "%type% ::")) tok = tok->tokAt(2); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 15ffc4266..2dd78f23e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2320,7 +2320,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::mapstr() == "(" && Token::Match(tok2->link()->next(), "(|[")) { + } else if (singleNameCount == 1 && Token::Match(tok2, "( [*&]") && Token::Match(tok2->link()->next(), "(|[")) { bracket = true; // Skip: Seems to be valid pointer to array or function pointer } else if (tok2->str() == "::") { singleNameCount = 0; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 58c939d4b..14e0ba104 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -1144,7 +1144,7 @@ private: "void(*p2)(char); \n" // pointer to function (char) returning void "int(*(*p3)(char))[10];\n" // pointer to function (char) returning pointer to array 10 of int "float(*(*p4)(char))(long); \n" // pointer to function (char) returning pointer to function (long) returning float - "short(*(*(p5) (char))(long))(double); \n" // pointer to function (char) returning pointer to function (long) returning pointer to function (double) returning short + "short(*(*(*p5) (char))(long))(double);\n" // pointer to function (char) returning pointer to function (long) returning pointer to function (double) returning short "int(*a1[10])(void); \n" // array 10 of pointer to function (void) returning int "float(*(*a2[10])(char))(long);\n" // array 10 of pointer to func (char) returning pointer to func (long) returning float "short(*(*(*a3[10])(char))(long))(double);\n" // array 10 of pointer to function (char) returning pointer to function (long) returning pointer to function (double) returning short diff --git a/test/testvarid.cpp b/test/testvarid.cpp index e964827b5..925dfa893 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -91,6 +91,7 @@ private: TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall3); TEST_CASE(varidFunctionCall4); // ticket #3280 + TEST_CASE(varidFunctionCall5); TEST_CASE(varidStl); TEST_CASE(varid_newauto); // not declaration: new const auto(0); TEST_CASE(varid_delete); @@ -1111,6 +1112,11 @@ private: tokenize(code2, false, "test.c")); } + void varidFunctionCall5() { + const char code[] = "void foo() { (f(x[2]))(x[2]); }"; + ASSERT_EQUALS("1: void foo ( ) { f ( x [ 2 ] ) ( x [ 2 ] ) ; }\n", + tokenize(code, false, "test.c")); + } void varidStl() { const std::string actual = tokenize(