ValueFlow: bool values
This commit is contained in:
parent
aaf19c1e4f
commit
f1ad7368f6
|
@ -1945,6 +1945,16 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat
|
||||||
std::list<ValueFlow::Value> values = tok->astOperand2()->values;
|
std::list<ValueFlow::Value> values = tok->astOperand2()->values;
|
||||||
const bool constValue = tok->astOperand2()->isNumber();
|
const bool constValue = tok->astOperand2()->isNumber();
|
||||||
|
|
||||||
|
if (tokenlist->isCPP() && Token::simpleMatch(var->typeStartToken(), "bool")) {
|
||||||
|
std::list<ValueFlow::Value>::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?
|
// Static variable initialisation?
|
||||||
if (var->isStatic() && var->nameToken() == tok->astOperand1()) {
|
if (var->isStatic() && var->nameToken() == tok->astOperand1()) {
|
||||||
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end(); ++it) {
|
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end(); ++it) {
|
||||||
|
|
|
@ -899,6 +899,12 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 123));
|
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"
|
code = "void f() {\n"
|
||||||
" int x = 123;\n"
|
" int x = 123;\n"
|
||||||
" a = sizeof(x);\n"
|
" a = sizeof(x);\n"
|
||||||
|
|
Loading…
Reference in New Issue