From 52e0e4453bc626f4fabfe1876b6a0693c352fc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 21 Apr 2014 16:14:49 +0200 Subject: [PATCH] Fixed #5646 (FP: pointer to array is not assigned a value.) --- lib/tokenize.cpp | 6 ++++++ test/testsimplifytokens.cpp | 2 +- test/testtokenize.cpp | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 719b826bf..d37f8d14c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7024,6 +7024,12 @@ bool Tokenizer::simplifyRedundantParentheses() tok->deleteThis(); ret = true; } + + if (Token::Match(tok->previous(), "%type% ( * %var% ) [") && tok->previous()->isStandardType()) { + tok->link()->deleteThis(); + tok->deleteThis(); + ret = true; + } } return ret; } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 51f72b3a2..83608e2d7 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -4799,7 +4799,7 @@ private: "type4 t4;"; // The expected result.. - const std::string expected("char ( * t1 ) [ 10 ] ; " + const std::string expected("char * t1 [ 10 ] ; " "char ( * ( * tp1 ) [ 2 ] ) [ 10 ] ; " "char ( & t2 ) [ 10 ] ; " "char ( & t3 ) [ x ] ; " diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 8773e5ab4..e7502db7e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -366,6 +366,7 @@ private: TEST_CASE(removeParentheses15); // Ticket #4142 TEST_CASE(removeParentheses16); // Ticket #4423 '*(x.y)=' TEST_CASE(removeParentheses17); // Don't remove parentheses in 'a ? b : (c>0 ? d : e);' + TEST_CASE(removeParentheses18); // 'float(*a)[2]' => 'float *a[2]' TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -4777,9 +4778,9 @@ private: void varid_pointerToArray() { ASSERT_EQUALS("\n\n##file 0\n" - "1: int ( * a1@1 ) [ 10 ] ;\n" + "1: int * a1@1 [ 10 ] ;\n" "2: void f1 ( ) {\n" - "3: int ( * a2@2 ) [ 10 ] ;\n" + "3: int * a2@2 [ 10 ] ;\n" "4: int ( & a3@3 ) [ 10 ] ;\n" "5: }\n" "6: struct A {\n" @@ -5629,6 +5630,10 @@ private: ASSERT_EQUALS("a ? b : ( c > 0 ? d : e ) ;", tokenizeAndStringify("a?b:(c>0?d:e);", false)); } + void removeParentheses18() { + ASSERT_EQUALS("float * a [ 2 ] ;", tokenizeAndStringify("float(*a)[2];", false)); + } + void tokenize_double() { const char code[] = "void f()\n" "{\n"