diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8a0d4df76..beb2ac9a2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9066,8 +9066,7 @@ void Tokenizer::simplifyWhile0() if (Token::simpleMatch(tok->next()->link(), ") {")) { Token *end = tok->next()->link(); end = end->next()->link(); - tok = tok->previous(); - eraseDeadCode(tok, end->next()); + eraseDeadCode(tok->previous(), end->next()); } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 759f2640e..1a94ce708 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2372,6 +2372,16 @@ private: ASSERT_EQUALS("void foo ( ) { exit ( 0 ) ; }", tokWithStdLib("void foo() { do { exit(0); } while (true); }")); + + // #6187 + tokWithStdLib("void foo() {\n" + " goto label;\n" + " for (int i = 0; i < 0; ++i) {\n" + " ;\n" + "label:\n" + " ;\n" + " }\n" + "}"); } void strcat1() {