diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index a6886cd03..0bd803b04 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1811,6 +1811,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } + // if break ; break ; => break ; + if (Token::Match(tok2->previous(), "[;{}] if break ; break ;")) + { + Token::eraseTokens(tok2, tok2->tokAt(4)); + done = false; + } + // Reduce "do { dealloc ; alloc ; } while(var) ;" => ";" if (Token::simpleMatch(tok2->next(), "do { dealloc ; alloc ; } while(var) ;")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 024b40fae..48b8f9f31 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -709,6 +709,7 @@ private: 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("; }", simplifycode("; loop { if break ; break ; } ; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while(!var) alloc ;"));