Fix issue 10022: Logical conjunction error between two completely unrelated members (#3094)

This commit is contained in:
Paul Fultz II 2021-01-29 03:26:57 -06:00 committed by GitHub
parent a9b7f0e27b
commit a81427f97f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 2 deletions

View File

@ -1231,13 +1231,27 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token
// TODO: Handle reverse conditions
if (Library::isContainerYield(cond1, Library::Container::Yield::EMPTY, "empty") &&
Library::isContainerYield(cond2->astOperand1(), Library::Container::Yield::SIZE, "size") &&
cond1->astOperand1()->astOperand1()->varId() == cond2->astOperand1()->astOperand1()->astOperand1()->varId()) {
isSameExpression(cpp,
true,
cond1->astOperand1()->astOperand1(),
cond2->astOperand1()->astOperand1()->astOperand1(),
library,
pure,
followVar,
errors)) {
return !isZeroBoundCond(cond2);
}
if (Library::isContainerYield(cond2, Library::Container::Yield::EMPTY, "empty") &&
Library::isContainerYield(cond1->astOperand1(), Library::Container::Yield::SIZE, "size") &&
cond2->astOperand1()->astOperand1()->varId() == cond1->astOperand1()->astOperand1()->astOperand1()->varId()) {
isSameExpression(cpp,
true,
cond2->astOperand1()->astOperand1(),
cond1->astOperand1()->astOperand1()->astOperand1(),
library,
pure,
followVar,
errors)) {
return !isZeroBoundCond(cond1);
}
}

View File

@ -77,6 +77,7 @@ private:
TEST_CASE(incorrectLogicOperator12);
TEST_CASE(incorrectLogicOperator13);
TEST_CASE(incorrectLogicOperator14);
TEST_CASE(incorrectLogicOperator15);
TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);
TEST_CASE(incorrectLogicOp_condSwapping);
TEST_CASE(testBug5895);
@ -1564,6 +1565,30 @@ private:
ASSERT_EQUALS("", errout.str());
}
void incorrectLogicOperator15()
{
// 10022
check("struct PipeRoute {\n"
" std::deque<int> points;\n"
" std::deque<int> estimates;\n"
"};\n"
"void CleanPipeRoutes(std::map<int, PipeRoute*>& pipeRoutes) {\n"
" for (auto it = pipeRoutes.begin(); it != pipeRoutes.end(); ) {\n"
" PipeRoute* curRoute = it->second;\n"
" if (curRoute->points.empty() && curRoute->estimates.size() != 2)\n"
" {\n"
" delete curRoute;\n"
" it = pipeRoutes.erase(it);\n"
" }\n"
" else\n"
" {\n"
" ++it;\n"
" }\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void secondAlwaysTrueFalseWhenFirstTrueError() {
check("void f(int x) {\n"
" if (x > 5 && x != 1)\n"