Skip to content

Commit

Permalink
Fix #12924 Syntax error on func(&data)[0]
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 10, 2024
1 parent b9912e0 commit fb5b346
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 fb5b346

Please sign in to comment.