Fix #767 (Tokenizer: Known variable variable not simplified)

http://sourceforge.net/apps/trac/cppcheck/ticket/767
This commit is contained in:
Reijo Tomperi 2009-10-20 23:58:46 +03:00
parent e5f13b4de2
commit 9d42194562
2 changed files with 10 additions and 1 deletions

View File

@ -3259,7 +3259,7 @@ bool Tokenizer::simplifyKnownVariables()
}
// Variable is used in calculation..
if (Token::Match(tok3, "[=+-*/[] %varid% [+-*/;]]", varid) ||
if (Token::Match(tok3, "[=+-*/[] %varid% [?+-*/;]]", varid) ||
Token::Match(tok3, "[=+-*/[] %varid% <<", varid) ||
Token::Match(tok3, "<< %varid% [+-*/;]]", varid))
{

View File

@ -1563,6 +1563,15 @@ private:
const char code[] = "( true ? abc . a : abc . b )";
ASSERT_EQUALS("( abc . a )", tok(code));
}
{
const char code[] = "void f()\n"
"{\n"
" bool x = false;\n"
" int b = x ? 44 : 3;\n"
"}\n";
ASSERT_EQUALS("void f ( ) { bool x ; x = false ; int b ; b = 3 ; }", tok(code));
}
}
void calculations()