diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index f5e332d71..0663b41ba 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1925,6 +1925,17 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } + // use; if| use; => use; + while (Token::Match(tok2, "[;{}] use ; if| use ;")) + { + Token *t = tok2->tokAt(2); + t->deleteNext(); + t->deleteNext(); + if (t->strAt(1) == ";") + t->deleteNext(); + done = false; + } + // use; if return; dealloc; => if return; dealloc; if (Token::Match(tok2, "[;{}] use ; if return ; dealloc ;")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index b2704e447..c1824d41e 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -658,6 +658,9 @@ private: ASSERT_EQUALS("alloc ;", simplifycode("alloc ; if ; if(var) ; ifv ; if(!var) ;")); ASSERT_EQUALS("alloc ;", simplifycode("alloc ; if ; else ;")); + // use.. + ASSERT_EQUALS("; alloc ; dealloc ; }", simplifycode("; alloc ; use ; use ; if use ; dealloc ; }")); + // if, else.. ASSERT_EQUALS("; alloc ; if break ; dealloc ;", simplifycode("; alloc ; if { break; } dealloc ;")); ASSERT_EQUALS("; alloc ; if continue ; dealloc ;", simplifycode("; alloc ; if { continue; } dealloc ;"));