Fixed #4293 (FP: Variable is not simplified, causing a false positive).
This commit is contained in:
parent
c8c50f0b25
commit
61365ea0e5
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -307,6 +307,7 @@ private:
|
|||
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 @@ private:
|
|||
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[] =
|
||||
|
|
Loading…
Reference in New Issue