Fix 11548: FP knownConditionTrueFalse with empty() == false (#4788)
* Fix 11548: FP knownConditionTrueFalse with empty() == false * Format * Fix test
This commit is contained in:
parent
a846bc2d99
commit
2b9af94b9a
|
@ -6157,22 +6157,24 @@ struct ConditionHandler {
|
|||
std::list<ValueFlow::Value> thenValues;
|
||||
std::list<ValueFlow::Value> elseValues;
|
||||
|
||||
bool inverted = cond.inverted;
|
||||
Token* ctx = skipNotAndCasts(condTok, &inverted);
|
||||
bool then = cond.inverted ? !inverted : true;
|
||||
|
||||
if (!Token::Match(condTok, "!=|=|(|.") && condTok != cond.vartok) {
|
||||
thenValues.insert(thenValues.end(), cond.true_values.cbegin(), cond.true_values.cend());
|
||||
if (allowImpossible && isConditionKnown(condTok, false))
|
||||
if (allowImpossible && isConditionKnown(ctx, !then))
|
||||
insertImpossible(elseValues, cond.false_values);
|
||||
}
|
||||
if (!Token::Match(condTok, "==|!")) {
|
||||
elseValues.insert(elseValues.end(), cond.false_values.cbegin(), cond.false_values.cend());
|
||||
if (allowImpossible && isConditionKnown(condTok, true)) {
|
||||
if (allowImpossible && isConditionKnown(ctx, then)) {
|
||||
insertImpossible(thenValues, cond.true_values);
|
||||
if (cond.isBool())
|
||||
insertNegateKnown(thenValues, cond.true_values);
|
||||
}
|
||||
}
|
||||
|
||||
bool inverted = cond.inverted;
|
||||
Token* ctx = skipNotAndCasts(condTok, &inverted);
|
||||
if (inverted)
|
||||
std::swap(thenValues, elseValues);
|
||||
|
||||
|
|
|
@ -6055,7 +6055,7 @@ private:
|
|||
" return 0;\n"
|
||||
" return v[0];\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(0U, tokenValues(code, "v [ 0 ]").size());
|
||||
ASSERT_EQUALS("", isImpossibleContainerSizeValue(tokenValues(code, "v [ 0 ]"), 0));
|
||||
|
||||
// container size => yields
|
||||
code = "void f() {\n"
|
||||
|
@ -6360,6 +6360,13 @@ private:
|
|||
" return x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 1));
|
||||
|
||||
// #11548
|
||||
code = "void f(const std::string& a, const std::string& b) {\n"
|
||||
" if (a.empty() && b.empty()) {}\n"
|
||||
" else if (a.empty() == false && b.empty() == false) {}\n"
|
||||
"}\n";
|
||||
ASSERT("" != isImpossibleContainerSizeValue(tokenValues(code, "a . empty ( ) == false"), 0));
|
||||
}
|
||||
|
||||
void valueFlowContainerElement()
|
||||
|
|
Loading…
Reference in New Issue