From ec87b09d89b0ba9ce7372f2670afa8675c849c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 17 Oct 2015 18:58:13 +0200 Subject: [PATCH] Fixed #7056 (iscast does not handle '(ulong)~0' properly, Tokenizer::simplifyCalculations wrongly simplifies '(ulong)~0' to 'ulong~0') --- lib/templatesimplifier.cpp | 2 +- test/testtokenize.cpp | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 61a1f17ed..01a0e6228 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1006,7 +1006,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) // keep parentheses here: Functor()(a ... ) // keep parentheses here: ) ( var ) ; if ((Token::Match(tok->next(), "( %name% ) ;|)|,|]") || - (Token::Match(tok->next(), "( %name% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&+-]")))) && + (Token::Match(tok->next(), "( %name% ) %cop%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&+-~]")))) && !tok->isName() && tok->str() != ">" && tok->str() != ")" && diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index dfe4e22cb..aa8a14230 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -955,12 +955,9 @@ private: // #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)); + ASSERT_EQUALS("; float angle ; angle = ( float ) - tilt ;", tokenizeAndStringify("; float angle = (float) -tilt;", true)); + ASSERT_EQUALS("; float angle ; angle = ( float ) + tilt ;", tokenizeAndStringify("; float angle = (float) +tilt;", true)); + ASSERT_EQUALS("; int a ; a = ( int ) ~ c ;", tokenizeAndStringify("; int a = (int)~c;", true)); } void removeCast14() { // const