Fix #12122 FP knownConditionTrueFalse with type traits (#5595)

This commit is contained in:
chrchr-github 2023-10-26 23:33:35 +02:00 committed by GitHub
parent 689187d82a
commit 6bc164e0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View File

@ -1506,12 +1506,8 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
if (cpp) {
if (tok1->str() == "." && tok1->astOperand1() && tok1->astOperand1()->str() == "this")
tok1 = tok1->astOperand2();
while (Token::simpleMatch(tok1, "::") && tok1->astOperand2())
tok1 = tok1->astOperand2();
if (tok2->str() == "." && tok2->astOperand1() && tok2->astOperand1()->str() == "this")
tok2 = tok2->astOperand2();
while (Token::simpleMatch(tok2, "::") && tok2->astOperand2())
tok2 = tok2->astOperand2();
}
// Skip double not
if (Token::simpleMatch(tok1, "!") && Token::simpleMatch(tok1->astOperand1(), "!") && !Token::simpleMatch(tok1->astParent(), "=") && astIsBoolLike(tok2)) {
@ -1523,20 +1519,26 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
const bool tok_str_eq = tok1->str() == tok2->str();
if (!tok_str_eq && isDifferentKnownValues(tok1, tok2))
return false;
if (isSameConstantValue(macro, tok1, tok2))
const Token *followTok1 = tok1, *followTok2 = tok2;
while (Token::simpleMatch(followTok1, "::") && followTok1->astOperand2())
followTok1 = followTok1->astOperand2();
while (Token::simpleMatch(followTok2, "::") && followTok2->astOperand2())
followTok2 = followTok2->astOperand2();
if (isSameConstantValue(macro, followTok1, followTok2))
return true;
// Follow variable
if (followVar && !tok_str_eq && (tok1->varId() || tok2->varId() || tok1->enumerator() || tok2->enumerator())) {
const Token * varTok1 = followVariableExpression(tok1, cpp, tok2);
if ((varTok1->str() == tok2->str()) || isSameConstantValue(macro, varTok1, tok2)) {
followVariableExpressionError(tok1, varTok1, errors);
return isSameExpression(cpp, macro, varTok1, tok2, library, true, followVar, errors);
if (followVar && !tok_str_eq && (followTok1->varId() || followTok2->varId() || followTok1->enumerator() || followTok2->enumerator())) {
const Token * varTok1 = followVariableExpression(followTok1, cpp, followTok2);
if ((varTok1->str() == followTok2->str()) || isSameConstantValue(macro, varTok1, followTok2)) {
followVariableExpressionError(followTok1, varTok1, errors);
return isSameExpression(cpp, macro, varTok1, followTok2, library, true, followVar, errors);
}
const Token * varTok2 = followVariableExpression(tok2, cpp, tok1);
if ((tok1->str() == varTok2->str()) || isSameConstantValue(macro, tok1, varTok2)) {
followVariableExpressionError(tok2, varTok2, errors);
return isSameExpression(cpp, macro, tok1, varTok2, library, true, followVar, errors);
const Token * varTok2 = followVariableExpression(followTok2, cpp, followTok1);
if ((followTok1->str() == varTok2->str()) || isSameConstantValue(macro, followTok1, varTok2)) {
followVariableExpressionError(followTok2, varTok2, errors);
return isSameExpression(cpp, macro, followTok1, varTok2, library, true, followVar, errors);
}
if ((varTok1->str() == varTok2->str()) || isSameConstantValue(macro, varTok1, varTok2)) {
followVariableExpressionError(tok1, varTok1, errors);

View File

@ -6900,6 +6900,12 @@ private:
"[test.cpp:14]: (style) The comparison '0 > S::E0' is always false.\n"
"[test.cpp:15]: (style) The comparison '0 > S::F::F0' is always false.\n",
errout.str());
check("template<typename T, typename U>\n" // #12122
"void f() {\n"
" static_assert(std::is_same<T, U>::value || std::is_integral<T>::value);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void duplicateExpressionLoop() {