From 9e916eec6613df10daad7086e219ac8a7e02a92d Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Tue, 7 Aug 2012 10:59:27 +0200 Subject: [PATCH] Fixed #4024 (Tokenizer::simplifyFlowControl removes pieces of code inside a class if 'exit' is a member function). --- lib/tokenize.cpp | 3 ++- test/testsimplifytokens.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f43f9e12f..7330e024f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3643,7 +3643,8 @@ void Tokenizer::simplifyFlowControl() tok = tok->next(); eraseDeadCode(tok, 0); - } else if (Token::Match(tok,"return|throw|exit|abort|goto")) { + } else if (Token::Match(tok,"return|goto") || + (Token::Match(tok,"exit|throw|abort") && !Token::Match(tok->previous(),"%type%"))) { //catch the first ';' for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { if (tok2->str() == "(" || tok2->str() == "[") { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 6ae3713fc..9e2631c4e 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3440,6 +3440,28 @@ private: "}"; ASSERT_EQUALS(expected, tok(code)); } + + { + const char code[] = "class Fred\n" + "{\n" + "public:\n" + " bool foo() const { return f; }\n" + " bool exit();\n" + "\n" + "private:\n" + " bool f;\n" + "};\n"; + const char expected[] = "class Fred " + "{" + " public:" + " bool foo ( ) const { return f ; }" + " bool exit ( ) ;" + "" + " private:" + " bool f ; " + "} ;"; + ASSERT_EQUALS(expected, tok(code)); + } } void strcat1() {