From 41b2a52915b976d72b15d5559b4924cac92749f4 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 21 Nov 2009 01:38:30 +0600 Subject: [PATCH] Fixed #990 (Tokenizer::simplifyIfAddBraces() handle case where statement after if doesn't end by semicolon) http://sourceforge.net/apps/trac/cppcheck/ticket/990 --- lib/tokenize.cpp | 7 +++++++ test/testtokenize.cpp | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c5489fd50..493375a9f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2339,6 +2339,13 @@ void Tokenizer::simplifyIfAddBraces() --indentlevel; if (indentlevel == 0 && parlevel == 0) break; + + else if (indentlevel < 0 && parlevel == 0) + { + // insert closing brace before this + tempToken = tempToken->previous(); + break; + } } else if (tempToken->str() == "(") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b9c444282..56e210165 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -64,6 +64,7 @@ private: TEST_CASE(ifAddBraces6); TEST_CASE(ifAddBraces7); TEST_CASE(ifAddBraces8); + TEST_CASE(ifAddBraces9); TEST_CASE(whileAddBraces); TEST_CASE(doWhileAddBraces); @@ -554,6 +555,23 @@ private: ASSERT_EQUALS("do { ; } while ( false ) ;", tokenizeAndStringify(code, true)); } + void ifAddBraces9() + { + // ticket #990 + const char code[] = + "{" + " for (int k=0; k