Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #4293 (FP: Variable is not simplified, causing a false positive).

  • Loading branch information...
commit 61365ea0e5035799bdd523184b884204a92d5a5e 1 parent c8c50f0
@edward-san edward-san authored
Showing with 18 additions and 2 deletions.
  1. +9 −2 lib/tokenize.cpp
  2. +9 −0 test/testtokenize.cpp
View
11 lib/tokenize.cpp
@@ -5848,7 +5848,12 @@ bool Tokenizer::simplifyKnownVariables()
// constants..
{
std::map<unsigned int, std::string> constantValues;
+ bool goback = false;
for (Token *tok = list.front(); tok; tok = tok->next()) {
+ if (goback) {
+ tok = tok->previous();
+ goback = false;
+ }
if (tok->isName() && Token::Match(tok, "static| const| static| %type% const| %var% = %any% ;")) {
bool isconst = false;
for (const Token *tok2 = tok; tok2->str() != "="; tok2 = tok2->next()) {
@@ -5878,10 +5883,12 @@ bool Tokenizer::simplifyKnownVariables()
constantValues[vartok->varId()] = valuetok->str();
// remove statement
- while (tok1->str() != ";")
- tok1->deleteThis();
+ while (tok1->next()->str() != ";")
+ tok1->deleteNext();
+ tok1->deleteNext();
tok1->deleteThis();
tok = tok1;
+ goback = true;
}
}
View
9 test/testtokenize.cpp
@@ -307,6 +307,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(simplify_constants);
TEST_CASE(simplify_constants2);
TEST_CASE(simplify_constants3);
+ TEST_CASE(simplify_constants4);
TEST_CASE(simplify_null);
TEST_CASE(simplifyMulAndParens); // Ticket #2784 + #3184
@@ -4791,6 +4792,14 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
}
+ void simplify_constants4() {
+ const char code[] = "static const int bSize = 4;\n"
+ "static const int aSize = 50;\n"
+ "const int x = bSize;\n"
+ "const int y = aSize;\n";
+ ASSERT_EQUALS("const int x = 4 ;\nconst int y = 50 ;", tokenizeAndStringify(code,true));
+ }
+
void simplify_null() {
{
const char code[] =
Please sign in to comment.
Something went wrong with that request. Please try again.