diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cdf5e563d..ca41cbbb5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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 diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0eab14217..ad7133e61 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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"));