From 9b8ffe72193dfb5af1c4e052e09eae487a89f3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 3 Nov 2011 20:01:31 +0100 Subject: [PATCH] Fixed #3248 (Tokenizer: better handling of char constants that are compared with numeric constants) --- lib/tokenize.cpp | 5 +++++ test/testpreprocessor.cpp | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b1721cc1e..d5f967ea9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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")) { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 51a83cbe8..b0d850c46 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -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() {