Skip to content

Commit ec87b09

Browse files
committed
Fixed cppcheck-opensource#7056 (iscast does not handle '(ulong)~0' properly, Tokenizer::simplifyCalculations wrongly simplifies '(ulong)~0' to 'ulong~0')
1 parent 30af2fc commit ec87b09

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
10061006
// keep parentheses here: Functor()(a ... )
10071007
// keep parentheses here: ) ( var ) ;
10081008
if ((Token::Match(tok->next(), "( %name% ) ;|)|,|]") ||
1009-
(Token::Match(tok->next(), "( %name% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&+-]")))) &&
1009+
(Token::Match(tok->next(), "( %name% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&+-~]")))) &&
10101010
!tok->isName() &&
10111011
tok->str() != ">" &&
10121012
tok->str() != ")" &&

test/testtokenize.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -955,12 +955,9 @@ class TestTokenizer : public TestFixture {
955955

956956
// #4899 - False positive on unused variable
957957
ASSERT_EQUALS("; float angle ; angle = tilt ;", tokenizeAndStringify("; float angle = (float) tilt;", true)); // status quo
958-
TODO_ASSERT_EQUALS("; float angle ; angle = - tilt ;",
959-
"; float angle ; angle = ( float ) - tilt ;",
960-
tokenizeAndStringify("; float angle = (float) -tilt;", true));
961-
TODO_ASSERT_EQUALS("; float angle ; angle = tilt ;",
962-
"; float angle ; angle = ( float ) + tilt ;",
963-
tokenizeAndStringify("; float angle = (float) +tilt;", true));
958+
ASSERT_EQUALS("; float angle ; angle = ( float ) - tilt ;", tokenizeAndStringify("; float angle = (float) -tilt;", true));
959+
ASSERT_EQUALS("; float angle ; angle = ( float ) + tilt ;", tokenizeAndStringify("; float angle = (float) +tilt;", true));
960+
ASSERT_EQUALS("; int a ; a = ( int ) ~ c ;", tokenizeAndStringify("; int a = (int)~c;", true));
964961
}
965962

966963
void removeCast14() { // const

0 commit comments

Comments
 (0)