Tokenizer: Fixed removeCast bug. Don't simplify (A)&b to A&b if A might be a type. Related with ticket: #4439

This commit is contained in:
Daniel Marjamki 2013-02-16 16:58:36 +01:00
parent 635b7d5a0e
commit 2a660fa3b4
2 changed files with 5 additions and 2 deletions

View File

@ -793,7 +793,8 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
// keep parentheses here: operator new [] (size_t);
// keep parentheses here: Functor()(a ... )
// keep parentheses here: ) ( var ) ;
if (Token::Match(tok->next(), "( %var% ) ;|)|,|]|%op%") &&
if ((Token::Match(tok->next(), "( %var% ) ;|)|,|]") ||
(Token::Match(tok->next(), "( %var% ) %op%") && (tok->tokAt(2)->varId()>0 || !Token::Match(tok->tokAt(4), "[*&]")))) &&
!tok->isName() &&
tok->str() != ">" &&
tok->str() != "]" &&

View File

@ -933,7 +933,9 @@ private:
}
void removeCast9() {
ASSERT_EQUALS("f ( ( double ) v1 * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true));
ASSERT_EQUALS("f ( ( double ) ( v1 ) * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true));
ASSERT_EQUALS("int v1 ; f ( ( double ) v1 * v2 )", tokenizeAndStringify("int v1; f((double)(v1)*v2)", true));
ASSERT_EQUALS("f ( ( A ) ( B ) & x )", tokenizeAndStringify("f((A)(B)&x)", true)); // #4439
}
void removeCast10() {