diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 592083eed..66b9fe8d0 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1860,13 +1860,20 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // Reduce "loop if break ; => ";" + // Reduce "loop if break|continue ; !!else" => ";" if (Token::Match(tok2->next(), "loop if break|continue ; !!else")) { Token::eraseTokens(tok2, tok2->tokAt(4)); done = false; } + // Reduce "loop { if break|continue ; !!else" => "loop {" + if (Token::Match(tok2, "loop { if break|continue ; !!else")) + { + Token::eraseTokens(tok2->next(), tok2->tokAt(5)); + done = false; + } + // Replace "do ; loop ;" with ";" if (Token::simpleMatch(tok2, "; loop ;")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index a8246de25..bb7164c5c 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -710,6 +710,7 @@ private: ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;")); ASSERT_EQUALS("; loop use ;", simplifycode("; loop { loop loop use ; } ;")); ASSERT_EQUALS("; }", simplifycode("; loop { if break ; break ; } ; }")); + ASSERT_EQUALS("; }", simplifycode("; loop { if continue ; if continue ; } ; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while(!var) alloc ;"));