diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 011c0c474..57fc6ceef 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3734,6 +3734,14 @@ bool Tokenizer::simplifyTokenList2() simplifyCasts(); + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::Match(tok, "%oror%|&& %num% %oror%|&&|,|)") || + Token::Match(tok, "[(,] %num% %oror%|&&")) { + tok = tok->next(); + tok->str(MathLib::isNullValue(tok->str()) ? "0" : "1"); + } + } + // Simplify simple calculations before replace constants, this allows the replacement of constants that are calculated // e.g. const static int value = sizeof(X)/sizeof(Y); simplifyCalculations(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index dd3228970..812ca7244 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5660,6 +5660,9 @@ private: // ticket #3964 - simplify numeric calculations in tokenization ASSERT_EQUALS("char a [ 10 ] ;", tokenizeAndStringify("char a[9+1];")); + + // ticket #4931 + ASSERT_EQUALS("dostuff ( 1 ) ;", tokenizeAndStringify("dostuff(9&&8);", true)); } void simplifyCompoundAssignment() {