diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 60fbe92968c..6beac75aec3 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4779,6 +4779,21 @@ static const Token* findInitListLambdaEnd(const Token* tok) return findLambdaEndScope(tok); } +static bool isPointerToArrayDeclarator(const Token* tok, const VariableMap& variableMap) +{ + if (!Token::Match(tok, "( *|&|&&")) + return false; + tok = tok->next(); + while (Token::Match(tok, "*|&|&&|const|volatile")) + tok = tok->next(); + if (tok && tok->isName()) { + if (variableMap.hasVariable(tok->str())) + return false; + tok = tok->next(); + } + return Token::simpleMatch(tok, ") ["); +} + void Tokenizer::setVarIdPass1() { const bool cpp = isCPP(); @@ -5058,7 +5073,8 @@ void Tokenizer::setVarIdPass1() if (tok3->isLiteral() || (tok3->isName() && (variableMap.hasVariable(tok3->str()) || - (tok3->strAt(-1) == "(" && Token::simpleMatch(tok3->next(), "(") && !Token::simpleMatch(tok3->linkAt(1)->next(), "(")))) || + (tok3->strAt(-1) == "(" && Token::simpleMatch(tok3->next(), "(") && !Token::simpleMatch(tok3->linkAt(1)->next(), "(") && + !isPointerToArrayDeclarator(tok3->next(), variableMap)))) || tok3->isOp() || tok3->str() == "(" || notstart.find(tok3->str()) != notstart.end()) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index b65d35db489..0722e698e9e 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -1632,12 +1632,22 @@ class TestVarID : public TestFixture { "A f(3);\n" "A f2(true);\n" "A g();\n" - "A e(int c);\n", dinit(TokenizeOptions, $.cpp = false)); + "A e(int c);\n" + "A h(T (*p)[16]);\n" + "int x(g(1)[0]);\n" + "A u(T (*)[16]);\n" + "A h3(T (*const p)[16]);\n" + "A h4(T (**p)[16]);\n", dinit(TokenizeOptions, $.cpp = false)); const char expected[] = "1: A f@1 ( 3 ) ;\n" "2: A f2@2 ( true ) ;\n" "3: A g ( ) ;\n" - "4: A e ( int c@3 ) ;\n"; + "4: A e ( int c@3 ) ;\n" + "5: A h ( T ( * p@4 ) [ 16 ] ) ;\n" + "6: int x@5 ( g ( 1 ) [ 0 ] ) ;\n" + "7: A u ( T ( * ) [ 16 ] ) ;\n" + "8: A h3 ( T ( * const p@6 ) [ 16 ] ) ;\n" + "9: A h4 ( T ( * * p@7 ) [ 16 ] ) ;\n"; ASSERT_EQUALS(expected, actual); }