diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 8af3d3a32..0dbb166c3 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1945,6 +1945,16 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat std::list values = tok->astOperand2()->values; const bool constValue = tok->astOperand2()->isNumber(); + if (tokenlist->isCPP() && Token::simpleMatch(var->typeStartToken(), "bool")) { + std::list::iterator it; + for (it = values.begin(); it != values.end(); ++it) { + if (it->isIntValue()) + it->intvalue = (it->intvalue != 0); + if (it->isTokValue()) + it ->intvalue = (it->tokvalue != 0); + } + } + // Static variable initialisation? if (var->isStatic() && var->nameToken() == tok->astOperand1()) { for (std::list::iterator it = values.begin(); it != values.end(); ++it) { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 308846c83..840ec8041 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -899,6 +899,12 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 3U, 123)); + code = "void f() {\n" + " bool x = 32;\n" + " a = x;\n" + "}"; + ASSERT_EQUALS(true, testValueOfX(code, 3U, 1)); + code = "void f() {\n" " int x = 123;\n" " a = sizeof(x);\n"