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