Fixed #980 (false negative: division by zero when using enum)

This commit is contained in:
Robert Reif 2011-01-16 11:24:58 +01:00 committed by Daniel Marjamäki
parent 0f6644e1ea
commit beb2db82a2
2 changed files with 35 additions and 1 deletions

View File

@ -2430,6 +2430,9 @@ bool Tokenizer::tokenize(std::istream &code,
// struct initialization (must be used before simplifyVarDecl) // struct initialization (must be used before simplifyVarDecl)
simplifyStructInit(); simplifyStructInit();
// Change initialisation of variable to assignment
simplifyInitVar();
// Split up variable declarations. // Split up variable declarations.
simplifyVarDecl(); simplifyVarDecl();
@ -2467,7 +2470,8 @@ bool Tokenizer::tokenize(std::istream &code,
// Change initialisation of variable to assignment // Change initialisation of variable to assignment
simplifyInitVar(); simplifyInitVar();
// Split up variable declarations.
simplifyVarDecl();
if (!preprocessorCondition) if (!preprocessorCondition)
{ {
@ -6083,6 +6087,7 @@ bool Tokenizer::simplifyLogicalOperators()
} }
// int i(0); => int i; i = 0; // int i(0); => int i; i = 0;
// int i(0), j; => int i; i = 0; int j;
void Tokenizer::simplifyInitVar() void Tokenizer::simplifyInitVar()
{ {
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
@ -6095,6 +6100,28 @@ void Tokenizer::simplifyInitVar()
{ {
tok = initVar(tok); tok = initVar(tok);
} }
else if (Token::Match(tok, "class|struct|union| %type% *| %var% ( &| %any% ) ,"))
{
Token *tok1 = tok;
while (tok1->str() != ",")
tok1 = tok1->next();
tok1->str(";");
Token *tok2 = tok;
if (Token::Match(tok2, "class|struct|union"))
{
tok1->insertToken(tok2->str());
tok1 = tok1->next();
tok2 = tok2->next();
}
tok1->insertToken(tok2->str());
tok1 = tok1->next();
tok2 = tok2->next();
if (tok2->str() == "*")
{
tok1->insertToken("*");
}
tok = initVar(tok);
}
} }
} }

View File

@ -6286,6 +6286,13 @@ private:
const char expected[] = "struct ABC { } ; static ABC abc ;"; const char expected[] = "struct ABC { } ; static ABC abc ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code, false));
} }
// ticket #980
{
const char code[] = "void f() { int A(1),B(2),C=3,D,E(5),F=6; }";
const char expected[] = "void f ( ) { int A ; A = 1 ; int B ; B = 2 ; int C ; C = 3 ; int D ; int E ; E = 5 ; int F ; F = 6 ; }";
ASSERT_EQUALS(expected, tok(code, false));
}
} }
void removeUnwantedKeywords() void removeUnwantedKeywords()