Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()) {
Expand Down
14 changes: 12 additions & 2 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading