simplify tokens: fixed bug when removing redundant parantheses around variable
This commit is contained in:
parent
91011b8450
commit
f4a8bc85f2
|
@ -926,7 +926,7 @@ void Tokenizer::simplifyTokenList()
|
|||
|
||||
// Remove parantheses around variable..
|
||||
// keep parantheses here: dynamic_cast<Fred *>(p);
|
||||
if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% )"))
|
||||
if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% ) [;),+-*/><]]"))
|
||||
{
|
||||
tok->deleteNext();
|
||||
tok = tok->next();
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
TEST_CASE(double_plus);
|
||||
TEST_CASE(redundant_plus);
|
||||
TEST_CASE(parantheses1);
|
||||
TEST_CASE(parantheses2);
|
||||
TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )"
|
||||
|
||||
TEST_CASE(elseif1);
|
||||
}
|
||||
|
@ -313,10 +313,15 @@ private:
|
|||
ASSERT_EQUALS("<= 110 ; ", tok(code1));
|
||||
}
|
||||
|
||||
void parantheses2()
|
||||
void paranthesesVar()
|
||||
{
|
||||
const char code1[] = "= (p);";
|
||||
ASSERT_EQUALS("= p ; ", tok(code1));
|
||||
// remove parantheses..
|
||||
ASSERT_EQUALS("= p ; ", tok("= (p);"));
|
||||
ASSERT_EQUALS("if ( a < p ) { ", tok("if(a<(p))"));
|
||||
|
||||
// keep parantheses..
|
||||
ASSERT_EQUALS("= ( char ) a ; ", tok("= (char)a;"));
|
||||
ASSERT_EQUALS("cast < char * > ( p ) ", tok("cast<char *>(p)"));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue