Skip to content

Commit 051584c

Browse files
Refs #12986: Tokenizer: don't simplify init list containing default-constructed element (#8640)
1 parent a7faefc commit 051584c

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3862,7 +3862,8 @@ void Tokenizer::simplifyRedundantConsecutiveBraces()
38623862
for (Token *tok = list.front(); tok;) {
38633863
if (Token::simpleMatch(tok, "= {")) {
38643864
tok = tok->linkAt(1);
3865-
} else if (Token::simpleMatch(tok, "{ {") && Token::simpleMatch(tok->linkAt(1), "} }")) {
3865+
} else if (Token::simpleMatch(tok, "{ {") && Token::simpleMatch(tok->linkAt(1), "} }") &&
3866+
!Token::Match(tok->previous(), "%name%")) {
38663867
//remove internal parentheses
38673868
tok->linkAt(1)->deleteThis();
38683869
tok->deleteNext();

test/testsimplifytokens.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ class TestSimplifyTokens : public TestFixture {
14221422
ASSERT_EQUALS("void f ( ) { }", tok("void f(){{{}}}"));
14231423
ASSERT_EQUALS("void f ( ) { for ( ; ; ) { } }", tok("void f () { for(;;){} }"));
14241424
ASSERT_EQUALS("void f ( ) { { scope_lock lock ; foo ( ) ; } { scope_lock lock ; bar ( ) ; } }", tok("void f () { {scope_lock lock; foo();} {scope_lock lock; bar();} }"));
1425+
ASSERT_EQUALS("std :: map < int , int > m { { } } ;", tok("std::map<int, int> m{ {} };"));
14251426
}
14261427

14271428
void simplifyOverride() { // ticket #5069

0 commit comments

Comments
 (0)