This commit is contained in:
parent
bf6bcafc56
commit
28a024ac4a
|
@ -1025,6 +1025,11 @@ static std::string conditionString(const Token * tok)
|
||||||
return tok->expressionString();
|
return tok->expressionString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isIfConstexpr(const Token* tok) {
|
||||||
|
const Token* const top = tok->astTop();
|
||||||
|
return top && Token::simpleMatch(top->astOperand1(), "if") && top->astOperand1()->isConstexpr();
|
||||||
|
}
|
||||||
|
|
||||||
void CheckCondition::checkIncorrectLogicOperator()
|
void CheckCondition::checkIncorrectLogicOperator()
|
||||||
{
|
{
|
||||||
const bool printStyle = mSettings->severity.isEnabled(Severity::style);
|
const bool printStyle = mSettings->severity.isEnabled(Severity::style);
|
||||||
|
@ -1144,10 +1149,12 @@ void CheckCondition::checkIncorrectLogicOperator()
|
||||||
ErrorPath errorPath;
|
ErrorPath errorPath;
|
||||||
|
|
||||||
// Opposite comparisons around || or && => always true or always false
|
// Opposite comparisons around || or && => always true or always false
|
||||||
if (!isfloat && isOppositeCond(tok->str() == "||", mTokenizer->isCPP(), tok->astOperand1(), tok->astOperand2(), mSettings->library, true, true, &errorPath)) {
|
const bool isLogicalOr(tok->str() == "||");
|
||||||
|
if (!isfloat && isOppositeCond(isLogicalOr, mTokenizer->isCPP(), tok->astOperand1(), tok->astOperand2(), mSettings->library, true, true, &errorPath)) {
|
||||||
const bool alwaysTrue(tok->str() == "||");
|
if (!isIfConstexpr(tok)) {
|
||||||
incorrectLogicOperatorError(tok, conditionString(tok), alwaysTrue, inconclusive, errorPath);
|
const bool alwaysTrue(isLogicalOr);
|
||||||
|
incorrectLogicOperatorError(tok, conditionString(tok), alwaysTrue, inconclusive, errorPath);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1494,6 +1501,9 @@ void CheckCondition::alwaysTrueFalse()
|
||||||
if (hasSizeof)
|
if (hasSizeof)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (isIfConstexpr(tok))
|
||||||
|
continue;
|
||||||
|
|
||||||
alwaysTrueFalseError(tok, &tok->values().front());
|
alwaysTrueFalseError(tok, &tok->values().front());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3438,6 +3438,15 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #9954
|
||||||
|
check("void f() {\n"
|
||||||
|
" const size_t a(8 * sizeof(short));\n"
|
||||||
|
" const size_t b(8 * sizeof(int));\n"
|
||||||
|
" if constexpr (a == 16 && b == 16) {}\n"
|
||||||
|
" else if constexpr (a == 16 && b == 32) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #9319
|
// #9319
|
||||||
check("struct S {\n"
|
check("struct S {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
|
|
Loading…
Reference in New Issue