Skip to content

Commit d0d2a0f

Browse files
committed
simplifyCalculations: Fix simplification of '( %num% )' when parentheses must be kept
1 parent 66d4614 commit d0d2a0f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
10871087
}
10881088

10891089
// Remove parentheses around number..
1090-
if (Token::Match(tok->tokAt(-2), "%any% ( %num% )") && !tok->tokAt(-2)->isName() && tok->strAt(-2) != ">") {
1090+
if (Token::Match(tok->tokAt(-2), "%op%|< ( %num% )") && !tok->tokAt(-2)->isName() && tok->strAt(-2) != ">") {
10911091
tok = tok->previous();
10921092
tok->deleteThis();
10931093
tok->deleteNext();

test/testsimplifytokens.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,9 @@ class TestSimplifyTokens : public TestFixture {
20592059
ASSERT_EQUALS("( y % 2 - 2 )", tok("(y % 2 - 2)"));
20602060

20612061
ASSERT_EQUALS("( 4 )", tok("(1 * 2 / 1 * 2)")); // #3722
2062+
2063+
// don't remove these spaces..
2064+
ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);"));
20622065
}
20632066

20642067
void comparisons() {

0 commit comments

Comments
 (0)