Fix issue 9865: false positive: knownConditionTrueFalse (#2764)
This commit is contained in:
parent
0a718694af
commit
ba84196dca
|
@ -4325,6 +4325,8 @@ struct ValueFlowConditionHandler {
|
|||
if (!values.empty()) {
|
||||
bool assign = false;
|
||||
visitAstNodes(parent->astOperand2(), [&](Token* tok2) {
|
||||
if (tok2 == tok)
|
||||
return ChildrenToVisit::done;
|
||||
if (isSameExpression(tokenlist->isCPP(), false, cond.vartok, tok2, settings->library, true, false))
|
||||
setTokenValue(tok2, values.front(), settings);
|
||||
else if (Token::Match(tok2, "++|--|=") && isSameExpression(tokenlist->isCPP(),
|
||||
|
|
|
@ -3412,6 +3412,18 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #9865
|
||||
check("void f(const std::string &s) {\n"
|
||||
" for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {\n"
|
||||
" const unsigned char c = static_cast<unsigned char>(*it);\n"
|
||||
" if (c == '0') {}\n"
|
||||
" else if ((c == 'a' || c == 'A')\n"
|
||||
" || (c == 'b' || c == 'B')) {}\n"
|
||||
" else {}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
}
|
||||
|
||||
void alwaysTrueInfer() {
|
||||
|
|
Loading…
Reference in New Issue