diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5c05f3429..5d78198ac 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7181,12 +7181,26 @@ void Tokenizer::simplifyGoto() if (tok->str() == "(" || tok->str() == "[") tok = tok->link(); - else if (tok->str() == "{") { - if (Token::Match(tok->tokAt(-2),"class|namespace|struct|union %var% {") || - Token::Match(tok->previous(),"namespace|struct|union {")) + else if (Token::Match(tok, "class|namespace|struct|union %type% :|{")) { + tok = tok->tokAt(2); + while (tok && !Token::Match(tok, "[;{=]")) + tok = tok->next(); + if (tok && tok->str() == "{") ++indentspecial; - else if ((!beginfunction && !indentlevel) || - (tok->previous() && tok->previous()->str() == "=")) + else if (!tok) + break; + else + continue; + } + + else if (Token::Match(tok, "namespace|struct|union {")) { + tok = tok->next(); + ++indentspecial; + } + + else if (tok->str() == "{") { + if ((!beginfunction && !indentlevel) || + (tok->previous() && tok->previous()->str() == "=")) tok = tok->link(); else ++indentlevel; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 987dcdeca..acb3bf855 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3130,6 +3130,54 @@ private: "}"; ASSERT_EQUALS(expected, tok(code)); } + + { + const char code[] = "class A" + "{" + " int a; " + " double b; " + " A() : b(3.22)" + " {" + " goto source ;" + " bleeh;" + " source:" + " a = 322;" + " }" + "}" + "class A1 : public A" + "{" + " int a1; " + " double b1; " + " A1() : b1(3.22)" + " {" + " goto source1 ;" + " bleeh1;" + " source1:" + " a = 322;" + " }" + "}"; + const char expected[] = "class A " + "{" + " int a ;" + " double b ;" + " A ( ) : b ( 3.22 )" + " {" + " a = 322 ;" + " return ;" + " } " + "} " + "class A1 : public A " + "{" + " int a1 ;" + " double b1 ;" + " A1 ( ) : b1 ( 3.22 )" + " {" + " a = 322 ;" + " return ;" + " } " + "}"; + ASSERT_EQUALS(expected, tok(code)); + } } void flowControl() {