From a6ac7478301bcd730b128351cc9b82dbdeb52f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 6 Jul 2009 11:45:14 +0200 Subject: [PATCH] tokenizer: Don't simplify declarations of static variables --- src/tokenize.cpp | 2 +- test/testtokenize.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 83c2df31d..c14f024b7 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -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; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 086a1dd04..8055c22a4 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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"