diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 4886f6986..7b3c18ab9 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1812,6 +1812,14 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } + // outer/inner if blocks. Remove outer condition.. + else if (Token::Match(tok2->next(), "if|if(var) { if return use ; }")) + { + tok2->tokAt(6)->deleteNext(); + Token::eraseTokens(tok2, tok2->tokAt(3)); + done = false; + } + else if (tok2->next() && tok2->next()->str() == "if") { // Delete empty if that is not followed by an else @@ -1902,14 +1910,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // Remove outer condition.. - else if (Token::Match(tok2->next(), "if { if return use ; }")) - { - tok2->tokAt(6)->deleteNext(); - Token::eraseTokens(tok2, tok2->tokAt(3)); - done = false; - } - continue; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 84ad6be75..36f47b27a 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -669,9 +669,7 @@ private: // remove outer if (#2733) ASSERT_EQUALS("alloc ; return ; }", simplifycode("alloc ; if { if return use ; } return ; }")); ASSERT_EQUALS("alloc ; return ; }", simplifycode("alloc ; if { if(var) return use ; } return ; }")); - TODO_ASSERT_EQUALS("alloc ; return ; }", - "alloc ; if(var) { if return use ; } return ; }", - simplifycode("alloc ; if(var) { if return use ; } return ; }")); + ASSERT_EQUALS("alloc ; return ; }", simplifycode("alloc ; if(var) { if return use ; } return ; }")); // "if ; .." ASSERT_EQUALS("; if xxx ;", simplifycode("; if ; else xxx ;"));