#11238: Fix regression (#4349)

* Fix #11238 FP knownConditionTrueFalse with constexpr?

* Modify isConstVarExpression()

* Use predicate

* Format

* #11238: Fix regression
This commit is contained in:
chrchr-github 2022-08-09 13:13:16 +02:00 committed by GitHub
parent 974e34490f
commit bdbd84ba98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -2784,7 +2784,7 @@ bool isConstVarExpression(const Token *tok, std::function<bool(const Token*)> sk
std::vector<const Token *> args = getArguments(tok);
if (args.empty() && tok->previous()->function() && tok->previous()->function()->isConstexpr())
return true;
return std::all_of(args.begin(), args.end(), [&](const Token* t) {
return !args.empty() && std::all_of(args.begin(), args.end(), [&](const Token* t) {
return isConstVarExpression(t, skipPredicate);
});
}

View File

@ -4289,6 +4289,14 @@ private:
" return f() == 1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("int g() { return -1; }\n"
"void f() {\n"
" if (g() == 1 && g() == -1) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'g()==1' is always false\n"
"[test.cpp:3]: (style) Condition 'g()==-1' is always true\n",
errout.str());
}
void alwaysTrueSymbolic()