diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index d96680b18..8dca31645 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1263,6 +1263,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) done = false; } + // Reduce "; if(!var) exit ;" => ";" + if (Token::Match(tok2, "; if(!var) exit ;")) + { + Token::eraseTokens(tok2, tok2->tokAt(3)); + done = false; + } + // Remove "catch ;" if (Token::simpleMatch(tok2->next(), "catch ;")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index f607daa6b..87275885e 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -456,11 +456,7 @@ private: // exit.. ASSERT_EQUALS(";", simplifycode("; if { alloc; exit; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if { use; exit; }")); - - // Todo.. - ASSERT_EQUALS("; alloc ; if(!var) exit ;", simplifycode("; alloc ; if(!var) { exit; }")); - TODO_ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if(!var) { exit; }")); - + ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if(!var) { exit; }")); TODO_ASSERT_EQUALS(";", simplifycode("; alloc ; if(var) { exit; }")); TODO_ASSERT_EQUALS(";", simplifycode("; alloc ; ifv { exit; }", false)); TODO_ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; ifv { exit; }", true));