From 8ecba0af90c5cd800f261d57999a2906d90f6d1e Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 15 Jan 2011 08:04:50 +0100 Subject: [PATCH] Fixed #2464 (False positive: not initialised/not assigned Static variable in copy constructors.) --- lib/tokenize.cpp | 7 +++++++ test/testsimplifytokens.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5d6117132..5f77ffb84 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8668,6 +8668,7 @@ void Tokenizer::simplifyStructDecl() // check for named struct/union if (Token::Match(tok, "struct|union %type% :|{")) { + Token *isStatic = tok->previous() && tok->previous()->str() == "static" ? tok->previous() : NULL; Token *type = tok->next(); Token *next = tok->tokAt(2); @@ -8684,6 +8685,12 @@ void Tokenizer::simplifyStructDecl() { tok->insertToken(";"); tok = tok->next(); + if (isStatic) + { + isStatic->deleteThis(); + tok->insertToken("static"); + tok = tok->next(); + } tok->insertToken(type->str().c_str()); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 0723e03af..68ab73a0f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -6271,6 +6271,13 @@ private: const char expected[] = ";"; ASSERT_EQUALS(expected, tok(code, false)); } + + // ticket 2464 + { + const char code[] = "static struct ABC { } abc ;"; + const char expected[] = "struct ABC { } ; static ABC abc ;"; + ASSERT_EQUALS(expected, tok(code, false)); + } } void removeUnwantedKeywords()