diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 138612c02..9dedb2808 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2054,6 +2054,7 @@ void Tokenizer::simplifyArrayAccessSyntax() if (Token::Match(tok, "%num% [ %name% ]")) { std::string temp = tok->str(); tok->str(tok->strAt(2)); + tok->varId(tok->tokAt(2)->varId()); tok->tokAt(2)->str(temp); } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 50682d84c..e3f2da661 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -132,7 +132,7 @@ private: TEST_CASE(simplifyOperator1); TEST_CASE(simplifyOperator2); - TEST_CASE(reverseArraySyntax) + TEST_CASE(simplifyArrayAccessSyntax) TEST_CASE(simplify_numeric_condition) TEST_CASE(simplify_condition); @@ -2523,8 +2523,9 @@ private: "}")); } - void reverseArraySyntax() { - ASSERT_EQUALS("a [ 13 ]", tok("13[a]")); + void simplifyArrayAccessSyntax() { + ASSERT_EQUALS("\n\n##file 0\n" + "1: int a@1 ; a@1 [ 13 ] ;\n", tokenizeDebugListing("int a; 13[a];")); } void simplify_numeric_condition() {