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;
|
continue;
|
||||||
}
|
}
|
||||||
// #4164 : ((unsigned char)1) => (1)
|
// #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());
|
const MathLib::bigint value = MathLib::toLongNumber(tok->next()->link()->next()->str());
|
||||||
unsigned int bits = 8 * _typeSize[tok->next()->link()->previous()->str()];
|
unsigned int bits = 8 * _typeSize[tok->next()->link()->previous()->str()];
|
||||||
if (!tok->tokAt(2)->isUnsigned())
|
if (!tok->tokAt(2)->isUnsigned())
|
||||||
|
@ -4970,11 +4970,11 @@ void Tokenizer::simplifyCasts()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((Token::Match(tok->next(), "( %type% *| *| *| ) *|&| %var%") && (tok->str() != ")" || tok->tokAt(2)->isStandardType())) ||
|
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% * *| *|&| ) *|&| %var%") ||
|
||||||
Token::Match(tok->next(), "( const| %type% %type% *| *| *| ) *|&| %var%") ||
|
Token::Match(tok->next(), "( const| %type% %type% *| *| *|&| ) *|&| %var%") ||
|
||||||
(!tok->isName() && (Token::Match(tok->next(), "( %type% * *| *| ) (") ||
|
(!tok->isName() && (Token::Match(tok->next(), "( %type% * *| *|&| ) (") ||
|
||||||
Token::Match(tok->next(), "( const| %type% %type% * *| *| ) (")))) {
|
Token::Match(tok->next(), "( const| %type% %type% * *| *|&| ) (")))) {
|
||||||
if (tok->isName() && tok->str() != "return")
|
if (tok->isName() && tok->str() != "return")
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ private:
|
||||||
TEST_CASE(removeCast13);
|
TEST_CASE(removeCast13);
|
||||||
TEST_CASE(removeCast14);
|
TEST_CASE(removeCast14);
|
||||||
TEST_CASE(removeCast15); // #5996 - don't remove cast in 'a+static_cast<int>(b?60:0)'
|
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
|
TEST_CASE(simplifyFloatCasts); // float casting a integer
|
||||||
|
|
||||||
|
@ -1033,6 +1034,11 @@ private:
|
||||||
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
|
void simplifyFloatCasts() { // float casting integers
|
||||||
// C-style casts
|
// C-style casts
|
||||||
ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;"));
|
ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;"));
|
||||||
|
|
Loading…
Reference in New Issue