diff --git a/src/tokenize.cpp b/src/tokenize.cpp index c3503ef86..be49e0b5f 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -471,13 +471,16 @@ void Tokenizer::setVarId() if (tok != _tokens && !Token::Match(tok, "[;{}(]")) continue; - if (!(firstMatch = Token::Match(tok->next(), "%type% *| %var%")) - && !Token::Match(tok->next(), "%type% %type% *| %var%")) + if ( Token::Match(tok, "[;{}(] %any%") ) + tok = tok->next(); + + if (!(firstMatch = Token::Match(tok, "%type% *| %var%")) + && !Token::Match(tok, "%type% %type% *| %var%")) continue; // Determine name of declared variable.. const char *varname = 0; - Token *tok2 = tok->tokAt(firstMatch ? 2 : 3); + Token *tok2 = tok->tokAt(firstMatch ? 1 : 2); while (tok2 && ! Token::Match(tok2, "[;[=(]")) { if (tok2->isName()) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1aff351c1..e2e43edfb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -878,7 +878,7 @@ private: void sizeof3() { - const char code[] = ";int i[10];\n" + const char code[] = "int i[10];\n" "sizeof(i[0]);\n"; // tokenize.. @@ -892,7 +892,7 @@ private: std::ostringstream ostr; for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) ostr << " " << tok->str(); - ASSERT_EQUALS(std::string(" ; int i [ 10 ] ; 4 ;"), ostr.str()); + ASSERT_EQUALS(std::string(" int i [ 10 ] ; 4 ;"), ostr.str()); } };