CheckOther:checkNegativeBitwiseShift: Fix FP when shift is protected by ?:
This commit is contained in:
parent
1ef1143609
commit
fb685f096a
|
@ -2663,6 +2663,17 @@ void CheckOther::checkNegativeBitwiseShift()
|
|||
continue;
|
||||
}
|
||||
|
||||
// bailout if operation is protected by ?:
|
||||
bool ternary = false;
|
||||
for (const Token *parent = tok; parent; parent = parent->astParent()) {
|
||||
if (Token::Match(parent, "?|:")) {
|
||||
ternary = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ternary)
|
||||
continue;
|
||||
|
||||
// Get negative rhs value. preferably a value which doesn't have 'condition'.
|
||||
const ValueFlow::Value *value = tok->astOperand2()->getValueLE(-1LL, _settings);
|
||||
if (value)
|
||||
|
|
|
@ -5490,6 +5490,9 @@ private:
|
|||
" std::cout << 3 << -1 ;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("x = y ? z << $-1 : 0;\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void incompleteArrayFill() {
|
||||
|
|
Loading…
Reference in New Issue