Fixed #5646 (FP: pointer to array is not assigned a value.)

This commit is contained in:
Daniel Marjamäki 2014-04-21 16:14:49 +02:00
parent c98beafb6d
commit 52e0e4453b
3 changed files with 14 additions and 3 deletions

View File

@ -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;
}

View File

@ -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 ] ; "

View File

@ -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"