Fixed #6278: Remove casts to references to pointers in Tokenizer::simplifyCasts()
This commit is contained in:
parent
b76619e0c1
commit
ad8749c0bd
|
@ -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;
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@ private:
|
|||
TEST_CASE(removeCast13);
|
||||
TEST_CASE(removeCast14);
|
||||
TEST_CASE(removeCast15); // #5996 - don't remove cast in 'a+static_cast<int>(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<int>(b?60:0)'
|
||||
ASSERT_EQUALS("a + ( b ? 60 : 0 ) ;",
|
||||
tokenizeAndStringify("a + static_cast<int>(b ? 60 : 0);",true));
|
||||
tokenizeAndStringify("a + static_cast<int>(b ? 60 : 0);", true));
|
||||
}
|
||||
|
||||
void removeCast16() { // #6278
|
||||
ASSERT_EQUALS("Get ( pArray ) ;",
|
||||
tokenizeAndStringify("Get((CObject*&)pArray);", true));
|
||||
}
|
||||
|
||||
void simplifyFloatCasts() { // float casting integers
|
||||
|
|
Loading…
Reference in New Issue