diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d31c06fe3..f0a8f6318 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4600,9 +4600,6 @@ void Tokenizer::simplifyIfAddBraces() continue; } - if (tok->previous() && !Token::Match(tok->previous(), ";|{|}|else|)|:")) - continue; - if (Token::Match(tok, "if|for|while (")) { // don't add "{}" around ";" in "do {} while();" (#609) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 02e75604d..76ddfc0cb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -80,6 +80,7 @@ private: TEST_CASE(ifAddBraces12); TEST_CASE(ifAddBraces13); TEST_CASE(ifAddBraces14); // #2610 - segfault: if()<{} + TEST_CASE(ifAddBraces15); // #2616 - unknown macro before if TEST_CASE(whileAddBraces); TEST_CASE(doWhileAddBraces); @@ -861,6 +862,12 @@ private: tokenizeAndStringify("if()<{}", false); } + void ifAddBraces15() + { + // ticket #2616 - unknown macro before if + ASSERT_EQUALS("{ A if ( x ) { y ( ) ; } }", tokenizeAndStringify("{A if(x)y();}", false)); + } + void whileAddBraces() {