Fixed ticket #565 (Tokenizer: simplify variable declaraion like 'int z = x >> 16')

http://sourceforge.net/apps/trac/cppcheck/ticket/565
This commit is contained in:
Slava Semushin 2009-08-08 17:33:07 +07:00
parent e93179dd9a
commit 50f7fa5828
2 changed files with 12 additions and 2 deletions

View File

@ -2415,12 +2415,12 @@ bool Tokenizer::simplifyVarDecl()
int parlevel = 0; int parlevel = 0;
while (tok2) while (tok2)
{ {
if (strchr("{(<", tok2->str()[0])) if (Token::Match(tok2, "[{(<]"))
{ {
++parlevel; ++parlevel;
} }
else if (strchr("})>", tok2->str()[0])) else if (Token::Match(tok2, "[})>]"))
{ {
if (parlevel <= 0) if (parlevel <= 0)
break; break;

View File

@ -132,6 +132,7 @@ private:
TEST_CASE(vardecl3); TEST_CASE(vardecl3);
TEST_CASE(vardecl4); TEST_CASE(vardecl4);
TEST_CASE(vardecl5); TEST_CASE(vardecl5);
TEST_CASE(vardecl6);
TEST_CASE(vardecl_stl); TEST_CASE(vardecl_stl);
TEST_CASE(volatile_variables); TEST_CASE(volatile_variables);
TEST_CASE(syntax_error); TEST_CASE(syntax_error);
@ -2240,6 +2241,15 @@ private:
ASSERT_EQUALS(code, tokenizeAndStringify(code)); ASSERT_EQUALS(code, tokenizeAndStringify(code));
} }
void vardecl6()
{
// ticket #565
const char code1[] = "int z = x >> 16;";
const char res1[] = "int z ; z = x >> 16 ;";
ASSERT_EQUALS(res1, tokenizeAndStringify(code1));
}
void volatile_variables() void volatile_variables()
{ {
const char code[] = "volatile int a=0;\n" const char code[] = "volatile int a=0;\n"