diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fe51596a0..8e2eef274 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6987,9 +6987,10 @@ void Tokenizer::simplifyGoto() break; --lev; } - if (!roundbraces && tok2->str() == "{") { + else if (!roundbraces && tok2->str() == "{") { ++lev; - } else if (!roundbraces && tok2->str() == "return") { + } + else if (!roundbraces && tok2->str() == "return") { ret = true; if (indentlevel == 1 && lev == 0) ret2 = true; @@ -6998,7 +6999,7 @@ void Tokenizer::simplifyGoto() token = token->next(); token->linenr(tok2->linenr()); token->varId(tok2->varId()); - if (ret2 && tok2->str() == ";") { + if (ret2 && roundbraces == 0 && tok2->str() == ";") { break; } if (token->str() == "(") { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f4908699d..9ba2c8dcb 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -161,10 +161,9 @@ private: // Simplify goto.. TEST_CASE(goto1); TEST_CASE(goto2); - // ticket #3138 - TEST_CASE(goto3); - // ticket #3459 - TEST_CASE(goto4); + TEST_CASE(goto3); // #3138 + TEST_CASE(goto4); // #3459 + TEST_CASE(goto5); // #3705 - return ({asm("");}); //remove dead code after flow control statements TEST_CASE(flowControl); @@ -3225,6 +3224,18 @@ private: ASSERT_EQUALS(expected, tok(code)); } + void goto5() { + const char code[] = "int foo() {\n" + " goto err;\n" + "err:\n" + " return ( { __asm__(X); } ); " + "}\n"; + ASSERT_EQUALS("int foo ( ) {" + " return { asm ( \"X\" ) ; } ;" + " return { asm ( \"X\" ) ; } ; " + "}", tok(code)); + } + void flowControl() { std::list beforedead; //beforedead.push_back("return");