tokenizer: Don't simplify declarations of static variables

This commit is contained in:
Daniel Marjamäki 2009-07-06 11:45:14 +02:00
parent c8493e31ef
commit a6ac747830
2 changed files with 11 additions and 2 deletions

View File

@ -2133,7 +2133,7 @@ bool Tokenizer::simplifyVarDecl()
Token *type0 = tok;
if (!Token::Match(type0, "%type%"))
continue;
if (Token::Match(type0, "else|return"))
if (Token::Match(type0, "else|return|static"))
continue;
bool isconst = false;

View File

@ -149,6 +149,7 @@ private:
TEST_CASE(vardecl2);
TEST_CASE(vardecl3);
TEST_CASE(vardecl4);
TEST_CASE(vardecl5);
TEST_CASE(volatile_variables);
TEST_CASE(syntax_error);
@ -939,7 +940,7 @@ private:
// result..
const std::string actual(tokenizer.tokens()->stringifyList(true));
const std::string expected("\n\n##file 0\n"
"1: static int i@1 ; i@1 = 1 ;\n"
"1: static int i@1 = 1 ;\n"
"2: void f ( )\n"
"3: {\n"
"4: int i@2 ; i@2 = 2 ;\n"
@ -2112,6 +2113,14 @@ private:
ASSERT_EQUALS(res4, tokenizeAndStringify(code4));
}
void vardecl5()
{
// don't simplify declarations of static variables
// "static int i = 0;" is not the same as "static int i; i = 0;"
const char code[] = "static int i = 0 ;";
ASSERT_EQUALS(code, tokenizeAndStringify(code));
}
void volatile_variables()
{
const char code[] = "volatile int a=0;\n"