Fixed #5174 (Tokenizer: member function 'abort' returns)

This commit is contained in:
Daniel Marjamäki 2013-12-14 11:12:48 +01:00
parent fdcb6634df
commit f599e3184c
2 changed files with 24 additions and 2 deletions

View File

@ -3953,7 +3953,6 @@ void Tokenizer::simplifyEmptyNamespaces()
void Tokenizer::simplifyFlowControl() void Tokenizer::simplifyFlowControl()
{ {
for (Token *begin = list.front(); begin; begin = begin->next()) { for (Token *begin = list.front(); begin; begin = begin->next()) {
if (begin->str() == "(" || begin->str() == "[" || if (begin->str() == "(" || begin->str() == "[" ||
@ -4000,7 +3999,9 @@ void Tokenizer::simplifyFlowControl()
eraseDeadCode(tok, 0); eraseDeadCode(tok, 0);
} else if (Token::Match(tok,"return|goto") || } else if (Token::Match(tok,"return|goto") ||
Token::Match(tok,"exit|abort") || Token::Match(tok->previous(), "[;{}] exit (") ||
(Token::Match(tok->previous(), "[;{}] %var% (") &&
_settings->library.isnoreturn(tok->str())) ||
(tok->str() == "throw" && !isC())) { (tok->str() == "throw" && !isC())) {
//TODO: ensure that we exclude user-defined 'exit|abort|throw', except for 'noreturn' //TODO: ensure that we exclude user-defined 'exit|abort|throw', except for 'noreturn'
//catch the first ';' //catch the first ';'

View File

@ -452,6 +452,8 @@ private:
TEST_CASE(simplifyArrayAddress); // Replace "&str[num]" => "(str + num)" TEST_CASE(simplifyArrayAddress); // Replace "&str[num]" => "(str + num)"
TEST_CASE(simplifyCharAt); TEST_CASE(simplifyCharAt);
TEST_CASE(simplifyOverride); // ticket #5069 TEST_CASE(simplifyOverride); // ticket #5069
TEST_CASE(simplifyFlowControl);
} }
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) {
@ -8297,6 +8299,25 @@ private:
tok(code, true)); tok(code, true));
} }
void simplifyFlowControl() {
const char code1[] = "void f() {\n"
" return;\n"
" y();\n"
"}";
ASSERT_EQUALS("void f ( ) { return ; }", tok(code1,true));
const char code2[] = "void f() {\n"
" exit();\n"
" y();\n"
"}";
ASSERT_EQUALS("void f ( ) { exit ( ) ; }", tok(code2,true));
const char code3[] = "void f() {\n"
" x.abort();\n"
" y();\n"
"}";
ASSERT_EQUALS("void f ( ) { x . abort ( ) ; y ( ) ; }", tok(code3,true));
}
}; };
REGISTER_TEST(TestSimplifyTokens) REGISTER_TEST(TestSimplifyTokens)