From fb5b346a922a2fa4be0db0bf62a6675861e818d3 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Thu, 11 Jul 2024 00:07:21 +0200 Subject: [PATCH] Fix #12924 Syntax error on func(&data)[0] --- lib/tokenize.cpp | 2 +- test/testvarid.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a8b41b5b176..3a4a595ed40 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; } diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 645ff6a7379..4a6b48bb0f1 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -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() {