Fixed #8241 (FP: Same expression on both sides of operator)

This commit is contained in:
Daniel Marjamäki 2017-10-16 17:39:50 +02:00
parent 2c61f40c35
commit 0425f1d46d
2 changed files with 7 additions and 0 deletions

View File

@ -5248,6 +5248,9 @@ void Tokenizer::simplifyPointerToStandardType()
if (!Token::Match(tok, "& %name% [ 0 ] !!["))
continue;
if (!Token::Match(tok->previous(), "[,(=]"))
continue;
// Remove '[ 0 ]' suffix
tok->next()->eraseTokens(tok->next(), tok->tokAt(5));
// Remove '&' prefix

View File

@ -4712,6 +4712,10 @@ private:
tokenizeAndStringify("char buf[100] ; readlink(path, &buf[0], 99);",
false, true, Settings::Native, "test.c"));
ASSERT_EQUALS("void foo ( char * c ) { if ( 1 == ( 1 & c [ 0 ] ) ) { } }",
tokenizeAndStringify("void foo(char *c) { if (1==(1 & c[0])) {} }",
false, true, Settings::Native, "test.c"));
// Simplification of unknown type - C only
ASSERT_EQUALS("foo data [ 100 ] ; something ( foo ) ;",
tokenizeAndStringify("foo data[100]; something(&foo[0]);", false, true, Settings::Native, "test.c"));