simplifyCalculations: Improved handling of casts (#4899)
This commit is contained in:
parent
0dddd424a4
commit
5d7518aa57
|
@ -840,7 +840,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
|
|||
// keep parentheses here: Functor()(a ... )
|
||||
// keep parentheses here: ) ( var ) ;
|
||||
if ((Token::Match(tok->next(), "( %var% ) ;|)|,|]") ||
|
||||
(Token::Match(tok->next(), "( %var% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&]")))) &&
|
||||
(Token::Match(tok->next(), "( %var% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&+-]")))) &&
|
||||
!tok->isName() &&
|
||||
tok->str() != ">" &&
|
||||
tok->str() != "]" &&
|
||||
|
|
|
@ -94,6 +94,7 @@ private:
|
|||
TEST_CASE(removeCast10);
|
||||
TEST_CASE(removeCast11);
|
||||
TEST_CASE(removeCast12);
|
||||
TEST_CASE(removeCast13);
|
||||
|
||||
TEST_CASE(inlineasm);
|
||||
|
||||
|
@ -1051,6 +1052,27 @@ private:
|
|||
ASSERT_EQUALS("; ( ( short * ) data ) [ 5 ] = 0 ;", tokenizeAndStringify("; ((short*)data)[5] = 0;", true));
|
||||
}
|
||||
|
||||
void removeCast13() {
|
||||
// casting deref / address of
|
||||
ASSERT_EQUALS("; int x ; x = * y ;", tokenizeAndStringify(";int x=(int)*y;",true));
|
||||
ASSERT_EQUALS("; int x ; x = & y ;", tokenizeAndStringify(";int x=(int)&y;",true));
|
||||
TODO_ASSERT_EQUALS("; int x ; x = ( INT ) * y ;",
|
||||
"; int x ; x = * y ;",
|
||||
tokenizeAndStringify(";int x=(INT)*y;",true)); // INT might be a variable
|
||||
TODO_ASSERT_EQUALS("; int x ; x = ( INT ) & y ;",
|
||||
"; int x ; x = & y ;",
|
||||
tokenizeAndStringify(";int x=(INT)&y;",true)); // INT might be a variable
|
||||
|
||||
// #4899 - False positive on unused variable
|
||||
ASSERT_EQUALS("; float angle ; angle = tilt ;", tokenizeAndStringify("; float angle = (float) tilt;", true)); // status quo
|
||||
TODO_ASSERT_EQUALS("; float angle ; angle = - tilt ;",
|
||||
"; float angle ; angle = ( float ) - tilt ;",
|
||||
tokenizeAndStringify("; float angle = (float) -tilt;", true));
|
||||
TODO_ASSERT_EQUALS("; float angle ; angle = tilt ;",
|
||||
"; float angle ; angle = ( float ) + tilt ;",
|
||||
tokenizeAndStringify("; float angle = (float) +tilt;", true));
|
||||
}
|
||||
|
||||
void inlineasm() {
|
||||
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };"));
|
||||
ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };"));
|
||||
|
|
Loading…
Reference in New Issue