Skip to content

Commit

Permalink
Fix #12924 Syntax error on func(&data)[0] (#6585)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jul 11, 2024
1 parent ba29f83 commit 5d3b528
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4328,7 +4328,7 @@ static bool setVarIdParseDeclaration(Token*& tok, const VariableMap& variableMap
}
if (Token::Match(tok3, "= %num%"))
return false;
if (bracket && Token::Match(tok1->previous(), "[(,]") && Token::Match(tok3, "[,)]"))
if (bracket && Token::Match(tok1->previous(), "[(,]") && Token::Match(tok3, ",|)|%cop%"))
return false;
}

Expand Down
9 changes: 9 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3279,6 +3279,15 @@ class TestVarID : public TestFixture {
" else x;\n"
" x;\n"
"}"));

ASSERT_EQUALS("1: const char * f ( int * ) ;\n" // #12924
"2: void g ( int i@1 ) {\n"
"3: if ( f ( & i@1 ) [ 0 ] == 'm' ) { }\n"
"4: }\n",
tokenize("const char *f(int*);\n"
"void g(int i) {\n"
" if (f(&i)[0] == 'm') {}\n"
"}\n", false));
}

void varid_globalScope() {
Expand Down

0 comments on commit 5d3b528

Please sign in to comment.