diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 279512db1..aee5fd833 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -920,7 +920,21 @@ void Preprocessor::simplifyCondition(const std::map &v } // simplify calculations.. - tokenizer.simplifyCalculations(); + bool modified = true; + while (modified) + { + modified = false; + tokenizer.simplifyCalculations(); + for (Token *tok = const_cast(tokenizer.tokens()); tok; tok = tok->next()) + { + if (Token::Match(tok, "! %num%")) + { + tok->deleteThis(); + tok->str(tok->str() == "0" ? "1" : "0"); + modified = true; + } + } + } if (Token::simpleMatch(tokenizer.tokens(), "( 1 )") || Token::simpleMatch(tokenizer.tokens(), "( 1 ||")) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index c2044de36..54f946f0d 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -611,10 +611,10 @@ private: cfg["ABC"] = ""; ASSERT_EQUALS(false, Preprocessor::match_cfg_def(cfg, "defined(A)")); - TODO_ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "!defined(A)")); + ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "!defined(A)")); ASSERT_EQUALS(false, Preprocessor::match_cfg_def(cfg, "!defined(ABC)&&!defined(DEF)")); - TODO_ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "!defined(A)&&!defined(B)")); + ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "!defined(A)&&!defined(B)")); } {