From cd5b95849dd3aa39153c80c94bae01e1edfd44e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 7 Feb 2010 15:00:19 +0100 Subject: [PATCH] Fixed #1361 (### Internal error in Cppcheck. Please report it) --- lib/tokenize.cpp | 8 ++++++++ test/testtokenize.cpp | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0e7a7bc7f..2516b1cd1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3102,7 +3102,15 @@ void Tokenizer::simplifyIfAddBraces() ++parlevel; else if (tempToken->str() == ")") + { + if (parlevel == 0) + { + tok->deleteThis(); + tempToken = 0; + break; + } --parlevel; + } else if (indentlevel == 0 && parlevel == 0 && tempToken->str() == ";") break; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 098a045e4..3ac625337 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -70,6 +70,7 @@ private: TEST_CASE(ifAddBraces6); TEST_CASE(ifAddBraces7); TEST_CASE(ifAddBraces9); + TEST_CASE(ifAddBraces10); TEST_CASE(whileAddBraces); TEST_CASE(doWhileAddBraces); @@ -623,6 +624,14 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } + void ifAddBraces10() + { + // ticket #1361 + const char code[] = "{ DEBUG(if (x) y; else z); }"; + const char expected[] = "{ DEBUG ( if ( x ) y ; else z ) ; }"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); + } + void whileAddBraces() { {