parent
84f102283b
commit
c88dceff95
|
@ -4714,7 +4714,7 @@ static std::list<ValueFlow::Value> truncateValues(std::list<ValueFlow::Value> va
|
|||
|
||||
static bool isVariableInit(const Token *tok)
|
||||
{
|
||||
return tok->str() == "(" &&
|
||||
return (tok->str() == "(" || tok->str() == "{") &&
|
||||
tok->isBinaryOp() &&
|
||||
tok->astOperand1()->variable() &&
|
||||
tok->astOperand1()->variable()->nameToken() == tok->astOperand1() &&
|
||||
|
|
|
@ -4296,6 +4296,22 @@ private:
|
|||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 1)); // value of x can be 1
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 3U, 2)); // value of x can't be 2
|
||||
|
||||
code = "bool f() {\n"
|
||||
" const int s( 4 );"
|
||||
" return s == 4;\n" // <- known value
|
||||
"}";
|
||||
value = valueOfTok(code, "==");
|
||||
ASSERT(value.isKnown());
|
||||
ASSERT_EQUALS(1, value.intvalue);
|
||||
|
||||
code = "bool f() {\n"
|
||||
" const int s{ 4 };"
|
||||
" return s == 4;\n" // <- known value
|
||||
"}";
|
||||
value = valueOfTok(code, "==");
|
||||
ASSERT(value.isKnown());
|
||||
ASSERT_EQUALS(1, value.intvalue);
|
||||
|
||||
// calculation with known result
|
||||
code = "int f(int x) { a = x & 0; }"; // <- & is 0
|
||||
value = valueOfTok(code, "&");
|
||||
|
|
Loading…
Reference in New Issue