valueflow: fix for ?:. the condition result is not a result of the ?.

This commit is contained in:
Daniel Marjamäki 2015-07-04 11:17:38 +02:00
parent fef251ac76
commit b8e77c8005
2 changed files with 8 additions and 1 deletions

View File

@ -333,7 +333,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
setTokenValue(parent,value);
}
else if (parent->str() == "?") {
else if (parent->str() == "?" && tok->str() == ":" && tok == parent->astOperand2()) {
// is condition only depending on 1 variable?
std::stack<const Token*> tokens;
tokens.push(parent->astOperand1());

View File

@ -1202,6 +1202,13 @@ private:
"}";
ASSERT_EQUALS(true, testValueOfX(code,3U,0));
ASSERT_EQUALS(true, testValueOfX(code,3U,0x80));
code = "int f(int a) {\n"
" int x = a & 0x80 ? 1 : 2;\n"
" return x;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code,3U,0));
ASSERT_EQUALS(false, testValueOfX(code,3U,0x80));
}
void valueFlowForLoop() {