Fixed #3248 (Tokenizer: better handling of char constants that are compared with numeric constants)

This commit is contained in:
Daniel Marjamäki 2011-11-03 20:01:31 +01:00
parent 73f3b2074b
commit 9b8ffe7219
2 changed files with 13 additions and 0 deletions

View File

@ -7272,6 +7272,11 @@ bool Tokenizer::simplifyCalculations()
ret = true;
}
if (tok->str()[0] == '\'' && tok->str().size() == 3 &&
Token::Match(tok->previous(), "(|&&|%oror% %any% ==|!=|<=|<|>=|> %num% &&|%oror%|)")) {
tok->str(MathLib::toString(tok->str()[1] & 0xff));
}
if (tok->isNumber()) {
if (tok->str() == "0") {
if (Token::Match(tok->previous(), "[+-|] 0")) {

View File

@ -123,6 +123,7 @@ private:
TEST_CASE(if_cond10);
TEST_CASE(if_cond11);
TEST_CASE(if_cond12);
TEST_CASE(if_cond13);
TEST_CASE(if_or_1);
TEST_CASE(if_or_2);
@ -1404,6 +1405,13 @@ private:
ASSERT_EQUALS("\n\n;\n\n", Preprocessor::getcode(filedata,"","",NULL,NULL));
}
void if_cond13() {
const char filedata[] = "#if ('A' == 0x41)\n"
"123\n"
"#endif\n";
ASSERT_EQUALS("\n123\n\n", Preprocessor::getcode(filedata,"","",NULL,NULL));
}
void if_or_1() {