From 00bae586e978a579f15c2c422dd025933f21b2c4 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 3 Dec 2011 01:58:26 +0100 Subject: [PATCH] Add 'throw' to the flow control statements list for simplification of dead code. --- lib/tokenize.cpp | 4 ++-- lib/tokenize.h | 2 +- test/testsimplifytokens.cpp | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cd00d1b28..823d2a85f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4504,8 +4504,8 @@ void Tokenizer::simplifyFlowControl() } eraseDeadCode(tok, beginindent->link()); - } else if (tok->str() == "return") { - //catch the first ';' after the return + } else if (tok->str() == "return" || tok->str() == "throw") { + //catch the first ';' after the return|trow statement for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { if (tok2->str() == "(" || tok2->str() == "[") { tok2 = tok2->link(); diff --git a/lib/tokenize.h b/lib/tokenize.h index e62ebe4e0..eeb37c57e 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -372,7 +372,7 @@ public: void simplifyGoto(); /** Simplify redundant code placed after control flow statements : - * 'return', 'goto', 'break' and 'continue' + * 'return', 'throw', 'goto', 'break' and 'continue' */ void simplifyFlowControl(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 7c8924b96..c14bef598 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3085,8 +3085,7 @@ private: void flowControl() { std::list beforedead; beforedead.push_back("return"); - beforedead.push_back("return 0"); - beforedead.push_back("return -1"); + beforedead.push_back("throw ( 10 )"); beforedead.push_back("goto labels"); beforedead.push_back("break"); beforedead.push_back("continue");