diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index f4d56be17..8740c1f54 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1855,10 +1855,9 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // Replace "loop callfunc ;" with ";" - if (Token::simpleMatch(tok2, "loop callfunc ;")) + // Replace "loop loop .." with "loop .." + if (Token::simpleMatch(tok2, "loop loop")) { - tok2->deleteThis(); tok2->deleteThis(); done = false; } @@ -1945,10 +1944,11 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // callfunc callfunc - while (Token::simpleMatch(tok2, "callfunc callfunc")) + // try/catch + if (Token::simpleMatch(tok2, "try ; catch exit ;")) { - tok2->deleteNext(); + Token::eraseTokens(tok2, tok2->tokAt(4)); + tok2->deleteThis(); done = false; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index f6ed93865..a5c4d5dda 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -707,6 +707,7 @@ private: ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }")); ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;")); ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;")); + ASSERT_EQUALS("; loop use ;", simplifycode("; loop { loop loop use ; } ;")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while(!var) alloc ;")); @@ -740,6 +741,9 @@ private: TODO_ASSERT_EQUALS(";", simplifycode("; alloc ; if(var) { exit; }")); TODO_ASSERT_EQUALS(";\n; alloc ;", simplifycode("; alloc ; ifv { exit; }")); + // try-catch + ASSERT_EQUALS("; }", simplifycode("; try ; catch exit ; }")); + // dealloc; dealloc; ASSERT_EQUALS("; alloc ; if dealloc ; dealloc ;", simplifycode("; alloc ; if { dealloc ; } dealloc ;"));