Support cast to ** in Tokenizer::simplifyCasts() (#7005)

This commit is contained in:
PKEuS 2015-09-28 16:08:14 +02:00
parent 590f1f1d66
commit e6467703b2
2 changed files with 2 additions and 1 deletions

View File

@ -4927,7 +4927,7 @@ void Tokenizer::simplifyCasts()
}
// Replace pointer casts of 0.. "(char *)0" => "0"
while (Token::Match(tok->next(), "( %type% %type%| * ) 0")) {
while (Token::Match(tok->next(), "( %type% %type%| * *| ) 0")) {
tok->linkAt(1)->next()->isCast(true);
Token::eraseTokens(tok, tok->next()->link()->next());
if (tok->str() == ")" && tok->link()->previous()) {

View File

@ -370,6 +370,7 @@ private:
ASSERT_EQUALS("class A { A operator* ( int ) ; } ;", tok("class A { A operator *(int); };"));
ASSERT_EQUALS("class A { A operator* ( int ) const ; } ;", tok("class A { A operator *(int) const; };"));
ASSERT_EQUALS("if ( p == 0 ) { ; }", tok("if (p == (char *)(char *)0);"));
ASSERT_EQUALS("if ( p == 0 ) { ; }", tok("if (p == (char **)0);"));
// no simplification as the cast may be important here. see #2897 for example
ASSERT_EQUALS("; * ( ( char * ) p + 1 ) = 0 ;", tok("; *((char *)p + 1) = 0;"));