From 2a660fa3b4cf827953c32b4f52577f28798b3dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=E4ki?= Date: Sat, 16 Feb 2013 16:58:36 +0100 Subject: [PATCH] Tokenizer: Fixed removeCast bug. Don't simplify (A)&b to A&b if A might be a type. Related with ticket: #4439 --- lib/templatesimplifier.cpp | 3 ++- test/testtokenize.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 0eb2efbfb..7ad8bc724 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -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() != "]" && diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d16229e57..c85138264 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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() {