Fixed #5996 (false positive: Clarify calculation precedence for '+' and '?'.)
This commit is contained in:
parent
264b94e0fa
commit
328cc7b8f5
|
@ -4886,20 +4886,13 @@ void Tokenizer::simplifyCasts()
|
|||
}
|
||||
}
|
||||
|
||||
while (Token::Match(tok->next(), "dynamic_cast|reinterpret_cast|const_cast|static_cast <")) {
|
||||
if (Token::Match(tok->next(), "dynamic_cast|reinterpret_cast|const_cast|static_cast <")) {
|
||||
Token *tok2 = tok->linkAt(2);
|
||||
|
||||
if (Token::simpleMatch(tok2, "> (")) {
|
||||
Token *closeBracket = tok2->next()->link();
|
||||
if (closeBracket) {
|
||||
Token::eraseTokens(tok, tok2->tokAt(2));
|
||||
closeBracket->deleteThis();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (Token::simpleMatch(tok2, "> ("))
|
||||
Token::eraseTokens(tok, tok2->next());
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ private:
|
|||
TEST_CASE(removeCast12);
|
||||
TEST_CASE(removeCast13);
|
||||
TEST_CASE(removeCast14);
|
||||
TEST_CASE(removeCast15); // #5996 - don't remove cast in 'a+static_cast<int>(b?60:0)'
|
||||
|
||||
TEST_CASE(simplifyFloatCasts); // float casting a integer
|
||||
|
||||
|
@ -1175,7 +1176,7 @@ private:
|
|||
|
||||
tokenizer.simplifyCasts();
|
||||
|
||||
ASSERT_EQUALS("t = & p ;", tokenizer.tokens()->stringifyList(0, false));
|
||||
ASSERT_EQUALS("t = ( & p ) ;", tokenizer.tokens()->stringifyList(0, false));
|
||||
}
|
||||
|
||||
void removeCast3() {
|
||||
|
@ -1257,6 +1258,11 @@ private:
|
|||
ASSERT_EQUALS("bar ( & ptr ) ;", tokenizeAndStringify("bar((const X**)&ptr);",true));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void simplifyFloatCasts() { // float casting integers
|
||||
// C-style casts
|
||||
ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;"));
|
||||
|
|
Loading…
Reference in New Issue