CheckCondition::checkIncorrectLogicOperator put conditions in single quotes
This commit is contained in:
parent
21ed807f8d
commit
87891b4128
|
@ -784,15 +784,15 @@ void CheckCondition::checkIncorrectLogicOperator()
|
||||||
const std::string text = cond1str + " " + tok->str() + " " + cond2str;
|
const std::string text = cond1str + " " + tok->str() + " " + cond2str;
|
||||||
incorrectLogicOperatorError(tok, text, alwaysTrue);
|
incorrectLogicOperatorError(tok, text, alwaysTrue);
|
||||||
} else if (printStyle && secondTrue) {
|
} else if (printStyle && secondTrue) {
|
||||||
const std::string text = "If " + cond1str + ", the comparison " + cond2str +
|
const std::string text = "If '" + cond1str + "', the comparison '" + cond2str +
|
||||||
" is always " + (secondTrue ? "true" : "false") + ".";
|
"' is always " + (secondTrue ? "true" : "false") + ".";
|
||||||
redundantConditionError(tok, text);
|
redundantConditionError(tok, text);
|
||||||
} else if (printStyle && firstTrue) {
|
} else if (printStyle && firstTrue) {
|
||||||
//const std::string text = "The comparison " + cond1str + " is always " +
|
//const std::string text = "The comparison " + cond1str + " is always " +
|
||||||
// (firstTrue ? "true" : "false") + " when " +
|
// (firstTrue ? "true" : "false") + " when " +
|
||||||
// cond2str + ".";
|
// cond2str + ".";
|
||||||
const std::string text = "If " + cond2str + ", the comparison " + cond1str +
|
const std::string text = "If '" + cond2str + "', the comparison '" + cond1str +
|
||||||
" is always " + (firstTrue ? "true" : "false") + ".";
|
"' is always " + (firstTrue ? "true" : "false") + ".";
|
||||||
redundantConditionError(tok, text);
|
redundantConditionError(tok, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -791,25 +791,25 @@ private:
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}");
|
"}");
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 3, the comparison x != 4 is always true.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 3', the comparison 'x != 4' is always true.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x!=4) && (x==3))\n"
|
" if ((x!=4) && (x==3))\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 3, the comparison x != 4 is always true.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 3', the comparison 'x != 4' is always true.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x==3) || (x!=4))\n"
|
" if ((x==3) || (x!=4))\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 3, the comparison x != 4 is always true.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 3', the comparison 'x != 4' is always true.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x!=4) || (x==3))\n"
|
" if ((x!=4) || (x==3))\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 3, the comparison x != 4 is always true.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 3', the comparison 'x != 4' is always true.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x==3) && (x!=3))\n"
|
" if ((x==3) && (x!=3))\n"
|
||||||
|
@ -839,7 +839,7 @@ private:
|
||||||
" if (x > 5 && x == 6)\n"
|
" if (x > 5 && x == 6)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 6, the comparison x > 5 is always true.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 6', the comparison 'x > 5' is always true.\n", errout.str());
|
||||||
|
|
||||||
// #3419
|
// #3419
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -948,7 +948,7 @@ private:
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x > 5, the comparison x != 1 is always true.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 5', the comparison 'x != 1' is always true.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if (x > 5 && x != 6)\n"
|
" if (x > 5 && x != 6)\n"
|
||||||
|
@ -962,7 +962,7 @@ private:
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x > 5, the comparison x != 1 is always true.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 5', the comparison 'x != 1' is always true.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x > 5) && (x != 6))\n"
|
" if ((x > 5) && (x != 6))\n"
|
||||||
|
@ -977,10 +977,10 @@ private:
|
||||||
" d = x >= 3 || x == 4;\n"
|
" d = x >= 3 || x == 4;\n"
|
||||||
" e = x <= 5 || x == 4;\n"
|
" e = x <= 5 || x == 4;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 4, the comparison x > 3 is always true.\n"
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 4', the comparison 'x > 3' is always true.\n"
|
||||||
"[test.cpp:3]: (style) Redundant condition: If x == 4, the comparison x < 5 is always true.\n"
|
"[test.cpp:3]: (style) Redundant condition: If 'x == 4', the comparison 'x < 5' is always true.\n"
|
||||||
"[test.cpp:4]: (style) Redundant condition: If x == 4, the comparison x >= 3 is always true.\n"
|
"[test.cpp:4]: (style) Redundant condition: If 'x == 4', the comparison 'x >= 3' is always true.\n"
|
||||||
"[test.cpp:5]: (style) Redundant condition: If x == 4, the comparison x <= 5 is always true.\n", errout.str());
|
"[test.cpp:5]: (style) Redundant condition: If 'x == 4', the comparison 'x <= 5' is always true.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x, bool& b) {\n"
|
check("void f(int x, bool& b) {\n"
|
||||||
" b = x > 5 || x != 1;\n"
|
" b = x > 5 || x != 1;\n"
|
||||||
|
@ -988,10 +988,10 @@ private:
|
||||||
" d = x >= 5 || x != 1;\n"
|
" d = x >= 5 || x != 1;\n"
|
||||||
" e = x <= 1 || x != 3;\n"
|
" e = x <= 1 || x != 3;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x > 5, the comparison x != 1 is always true.\n"
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 5', the comparison 'x != 1' is always true.\n"
|
||||||
"[test.cpp:3]: (style) Redundant condition: If x < 1, the comparison x != 3 is always true.\n"
|
"[test.cpp:3]: (style) Redundant condition: If 'x < 1', the comparison 'x != 3' is always true.\n"
|
||||||
"[test.cpp:4]: (style) Redundant condition: If x >= 5, the comparison x != 1 is always true.\n"
|
"[test.cpp:4]: (style) Redundant condition: If 'x >= 5', the comparison 'x != 1' is always true.\n"
|
||||||
"[test.cpp:5]: (style) Redundant condition: If x <= 1, the comparison x != 3 is always true.\n", errout.str());
|
"[test.cpp:5]: (style) Redundant condition: If 'x <= 1', the comparison 'x != 3' is always true.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x, bool& b) {\n"
|
check("void f(int x, bool& b) {\n"
|
||||||
" b = x > 6 && x > 5;\n"
|
" b = x > 6 && x > 5;\n"
|
||||||
|
@ -999,10 +999,10 @@ private:
|
||||||
" d = x < 6 && x < 5;\n"
|
" d = x < 6 && x < 5;\n"
|
||||||
" e = x < 5 || x < 6;\n"
|
" e = x < 5 || x < 6;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x > 6, the comparison x > 5 is always true.\n"
|
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 6', the comparison 'x > 5' is always true.\n"
|
||||||
"[test.cpp:3]: (style) Redundant condition: If x > 6, the comparison x > 5 is always true.\n"
|
"[test.cpp:3]: (style) Redundant condition: If 'x > 6', the comparison 'x > 5' is always true.\n"
|
||||||
"[test.cpp:4]: (style) Redundant condition: If x < 5, the comparison x < 6 is always true.\n"
|
"[test.cpp:4]: (style) Redundant condition: If 'x < 5', the comparison 'x < 6' is always true.\n"
|
||||||
"[test.cpp:5]: (style) Redundant condition: If x < 5, the comparison x < 6 is always true.\n", errout.str());
|
"[test.cpp:5]: (style) Redundant condition: If 'x < 5', the comparison 'x < 6' is always true.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void incorrectLogicOp_condSwapping() {
|
void incorrectLogicOp_condSwapping() {
|
||||||
|
@ -1500,7 +1500,7 @@ private:
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
#else
|
#else
|
||||||
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (style) Redundant condition: If init == 9894494448401390090, the comparison init == 9965707617509186058 is always true.\n", errout.str());
|
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (style) Redundant condition: If 'init == 9894494448401390090', the comparison 'init == 9965707617509186058' is always true.\n", errout.str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue