From ad8749c0bd621de51e64aad456df8dfd92f00e61 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 18 Nov 2014 19:23:03 +0100 Subject: [PATCH] Fixed #6278: Remove casts to references to pointers in Tokenizer::simplifyCasts() --- lib/tokenize.cpp | 12 ++++++------ test/testtokenize.cpp | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 643246af1..2240c814d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4959,7 +4959,7 @@ void Tokenizer::simplifyCasts() continue; } // #4164 : ((unsigned char)1) => (1) - if (Token::Match(tok->next(), "( unsigned| %type% ) %num%") && tok->next()->link()->previous()->isStandardType()) { + if (Token::Match(tok->next(), "( %type% ) %num%") && tok->next()->link()->previous()->isStandardType()) { const MathLib::bigint value = MathLib::toLongNumber(tok->next()->link()->next()->str()); unsigned int bits = 8 * _typeSize[tok->next()->link()->previous()->str()]; if (!tok->tokAt(2)->isUnsigned()) @@ -4970,11 +4970,11 @@ void Tokenizer::simplifyCasts() continue; } - while ((Token::Match(tok->next(), "( %type% *| *| *| ) *|&| %var%") && (tok->str() != ")" || tok->tokAt(2)->isStandardType())) || - Token::Match(tok->next(), "( const| %type% * *| *| ) *|&| %var%") || - Token::Match(tok->next(), "( const| %type% %type% *| *| *| ) *|&| %var%") || - (!tok->isName() && (Token::Match(tok->next(), "( %type% * *| *| ) (") || - Token::Match(tok->next(), "( const| %type% %type% * *| *| ) (")))) { + while ((Token::Match(tok->next(), "( %type% *| *| *|&| ) *|&| %var%") && (tok->str() != ")" || tok->tokAt(2)->isStandardType())) || + Token::Match(tok->next(), "( const| %type% * *| *|&| ) *|&| %var%") || + Token::Match(tok->next(), "( const| %type% %type% *| *| *|&| ) *|&| %var%") || + (!tok->isName() && (Token::Match(tok->next(), "( %type% * *| *|&| ) (") || + Token::Match(tok->next(), "( const| %type% %type% * *| *|&| ) (")))) { if (tok->isName() && tok->str() != "return") break; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 97f864e35..f217d210a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -96,6 +96,7 @@ private: TEST_CASE(removeCast13); TEST_CASE(removeCast14); TEST_CASE(removeCast15); // #5996 - don't remove cast in 'a+static_cast(b?60:0)' + TEST_CASE(removeCast16); // #6278 TEST_CASE(simplifyFloatCasts); // float casting a integer @@ -1030,7 +1031,12 @@ private: void removeCast15() { // #5996 - don't remove cast in 'a+static_cast(b?60:0)' ASSERT_EQUALS("a + ( b ? 60 : 0 ) ;", - tokenizeAndStringify("a + static_cast(b ? 60 : 0);",true)); + tokenizeAndStringify("a + static_cast(b ? 60 : 0);", true)); + } + + void removeCast16() { // #6278 + ASSERT_EQUALS("Get ( pArray ) ;", + tokenizeAndStringify("Get((CObject*&)pArray);", true)); } void simplifyFloatCasts() { // float casting integers