diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 91ac7b4ec..1bf120ee2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -723,36 +723,34 @@ void CheckOther::checkIncorrectLogicOperator() struct Condition { const char *before; - bool beforeEqual; Position position1; const char *op1TokStr; const char *op2TokStr; Position position2; const char *op3TokStr; const char *after; - bool afterEqual; Relation relation; bool state; } conditions[] = { - { "&&", false, NA, "!=", "||", NA, "!=", "&&", false, NotEqual, true }, // (x != 1) || (x != 3) <- always true - { "(", true, NA, "==", "&&", NA, "==", ")", true, NotEqual, false }, // (x == 1) && (x == 3) <- always false - { "(", true, First, "<", "&&", First, ">", ")", true, LessEqual, false }, // (x < 1) && (x > 3) <- always false - { "(", true, First, ">", "&&", First, "<", ")", true, MoreEqual, false }, // (x > 3) && (x < 1) <- always false - { "(", true, Second, ">", "&&", First, ">", ")", true, LessEqual, false }, // (1 > x) && (x > 3) <- always false - { "(", true, First, ">", "&&", Second, ">", ")", true, MoreEqual, false }, // (x > 3) && (1 > x) <- always false - { "(", true, First, "<", "&&", Second, "<", ")", true, LessEqual, false }, // (x < 1) && (3 < x) <- always false - { "(", true, Second, "<", "&&", First, "<", ")", true, MoreEqual, false }, // (3 < x) && (x < 1) <- always false - { "(", true, Second, ">", "&&", Second, "<", ")", true, LessEqual, false }, // (1 > x) && (3 < x) <- always false - { "(", true, Second, "<", "&&", Second, ">", ")", true, MoreEqual, false }, // (3 < x) && (1 > x) <- always false - { "(", true, First , ">|>=", "||", First, "<|<=", ")", true, Less, true }, // (x > 3) || (x < 10) <- always true - { "(", true, First , "<|<=", "||", First, ">|>=", ")", true, More, true }, // (x < 10) || (x > 3) <- always true - { "(", true, Second, "<|<=", "||", First, "<|<=", ")", true, Less, true }, // (3 < x) || (x < 10) <- always true - { "(", true, First, "<|<=", "||", Second, "<|<=", ")", true, More, true }, // (x < 10) || (3 < x) <- always true - { "(", true, First, ">|>=", "||", Second, ">|>=", ")", true, Less, true }, // (x > 3) || (10 > x) <- always true - { "(", true, Second, ">|>=", "||", First, ">|>=", ")", true, More, true }, // (10 > x) || (x > 3) <- always true - { "(", true, Second, "<|<=", "||", Second, ">|<=", ")", true, Less, true }, // (3 < x) || (10 > x) <- always true - { "(", true, Second, ">|>=", "||", Second, "<|<=", ")", true, More, true }, // (10 > x) || (3 < x) <- always true + { "!!&&", NA, "!=", "||", NA, "!=", "!!&&", NotEqual, true }, // (x != 1) || (x != 3) <- always true + { "(", NA, "==", "&&", NA, "==", ")", NotEqual, false }, // (x == 1) && (x == 3) <- always false + { "(", First, "<", "&&", First, ">", ")", LessEqual, false }, // (x < 1) && (x > 3) <- always false + { "(", First, ">", "&&", First, "<", ")", MoreEqual, false }, // (x > 3) && (x < 1) <- always false + { "(", Second, ">", "&&", First, ">", ")", LessEqual, false }, // (1 > x) && (x > 3) <- always false + { "(", First, ">", "&&", Second, ">", ")", MoreEqual, false }, // (x > 3) && (1 > x) <- always false + { "(", First, "<", "&&", Second, "<", ")", LessEqual, false }, // (x < 1) && (3 < x) <- always false + { "(", Second, "<", "&&", First, "<", ")", MoreEqual, false }, // (3 < x) && (x < 1) <- always false + { "(", Second, ">", "&&", Second, "<", ")", LessEqual, false }, // (1 > x) && (3 < x) <- always false + { "(", Second, "<", "&&", Second, ">", ")", MoreEqual, false }, // (3 < x) && (1 > x) <- always false + { "(", First , ">|>=", "||", First, "<|<=", ")", Less, true }, // (x > 3) || (x < 10) <- always true + { "(", First , "<|<=", "||", First, ">|>=", ")", More, true }, // (x < 10) || (x > 3) <- always true + { "(", Second, "<|<=", "||", First, "<|<=", ")", Less, true }, // (3 < x) || (x < 10) <- always true + { "(", First, "<|<=", "||", Second, "<|<=", ")", More, true }, // (x < 10) || (3 < x) <- always true + { "(", First, ">|>=", "||", Second, ">|>=", ")", Less, true }, // (x > 3) || (10 > x) <- always true + { "(", Second, ">|>=", "||", First, ">|>=", ")", More, true }, // (10 > x) || (x > 3) <- always true + { "(", Second, "<|<=", "||", Second, ">|<=", ")", Less, true }, // (3 < x) || (10 > x) <- always true + { "(", Second, ">|>=", "||", Second, "<|<=", ")", More, true }, // (10 > x) || (3 < x) <- always true }; for (unsigned int i = 0; i < (sizeof(conditions) / sizeof(conditions[0])); i++) @@ -772,10 +770,10 @@ void CheckOther::checkIncorrectLogicOperator() if (!Token::Match(op3Tok, conditions[i].op3TokStr)) continue; - if (!((conditions[i].beforeEqual && (conditions[i].before == logicTok->strAt(-1))) || (!conditions[i].beforeEqual && (conditions[i].before != logicTok->strAt(-1))))) + if (!Token::Match(logicTok->previous(), conditions[i].before)) continue; - if (!((conditions[i].afterEqual && (conditions[i].after == nextTok->str())) || (!conditions[i].afterEqual && (conditions[i].after != nextTok->str())))) + if (!Token::Match(nextTok, conditions[i].after)) continue; if ((conditions[i].relation == Equal && MathLib::isEqual(firstConstant, secondConstant)) ||