From f94aab35e70c96c1116aff1818d497ed976251d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 26 Aug 2009 18:46:56 +0200 Subject: [PATCH] Fixed #498 (Tokenizer: simplify 'goto') --- src/tokenize.cpp | 9 +++++++-- test/testsimplifytokens.cpp | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 3d5c730d9..fda467395 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -3121,7 +3121,12 @@ void Tokenizer::simplifyGoto() for (Token *tok = _tokens; tok; tok = (tok ? tok->next() : NULL)) { if (tok->str() == "{") - ++indentlevel; + { + if (beginfunction == 0 && indentlevel == 0 && tok->link()) + tok = tok->link(); + else + ++indentlevel; + } else if (tok->str() == "}") { @@ -3144,7 +3149,7 @@ void Tokenizer::simplifyGoto() else if (Token::Match(tok, "goto %var% ;")) gotos.push_back(tok); - else if (indentlevel == 1 && Token::Match(tok, "%var% :")) + else if (indentlevel == 1 && Token::Match(tok->previous(), "[};] %var% :")) { // Is this label at the end.. bool end = false; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 6d44e90f3..304a91782 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1261,6 +1261,11 @@ private: ASSERT_EQUALS(expect, tok(code)); } + + { + const char code[] = "class NoLabels { bool varOne : 1 ; bool varTwo : 1 ; } ;"; + ASSERT_EQUALS(code, tok(code)); + } } };