Fixed #5174 (Tokenizer: member function 'abort' returns)
This commit is contained in:
parent
fdcb6634df
commit
f599e3184c
|
@ -3953,7 +3953,6 @@ void Tokenizer::simplifyEmptyNamespaces()
|
|||
|
||||
void Tokenizer::simplifyFlowControl()
|
||||
{
|
||||
|
||||
for (Token *begin = list.front(); begin; begin = begin->next()) {
|
||||
|
||||
if (begin->str() == "(" || begin->str() == "[" ||
|
||||
|
@ -4000,7 +3999,9 @@ void Tokenizer::simplifyFlowControl()
|
|||
eraseDeadCode(tok, 0);
|
||||
|
||||
} 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())) {
|
||||
//TODO: ensure that we exclude user-defined 'exit|abort|throw', except for 'noreturn'
|
||||
//catch the first ';'
|
||||
|
|
|
@ -452,6 +452,8 @@ private:
|
|||
TEST_CASE(simplifyArrayAddress); // Replace "&str[num]" => "(str + num)"
|
||||
TEST_CASE(simplifyCharAt);
|
||||
TEST_CASE(simplifyOverride); // ticket #5069
|
||||
|
||||
TEST_CASE(simplifyFlowControl);
|
||||
}
|
||||
|
||||
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) {
|
||||
|
@ -8297,6 +8299,25 @@ private:
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue