Skip to content

Commit 87891b4

Browse files
committed
CheckCondition::checkIncorrectLogicOperator put conditions in single quotes
1 parent 21ed807 commit 87891b4

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

lib/checkcondition.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,15 +784,15 @@ void CheckCondition::checkIncorrectLogicOperator()
784784
const std::string text = cond1str + " " + tok->str() + " " + cond2str;
785785
incorrectLogicOperatorError(tok, text, alwaysTrue);
786786
} else if (printStyle && secondTrue) {
787-
const std::string text = "If " + cond1str + ", the comparison " + cond2str +
788-
" is always " + (secondTrue ? "true" : "false") + ".";
787+
const std::string text = "If '" + cond1str + "', the comparison '" + cond2str +
788+
"' is always " + (secondTrue ? "true" : "false") + ".";
789789
redundantConditionError(tok, text);
790790
} else if (printStyle && firstTrue) {
791791
//const std::string text = "The comparison " + cond1str + " is always " +
792792
// (firstTrue ? "true" : "false") + " when " +
793793
// cond2str + ".";
794-
const std::string text = "If " + cond2str + ", the comparison " + cond1str +
795-
" is always " + (firstTrue ? "true" : "false") + ".";
794+
const std::string text = "If '" + cond2str + "', the comparison '" + cond1str +
795+
"' is always " + (firstTrue ? "true" : "false") + ".";
796796
redundantConditionError(tok, text);
797797
}
798798
}

test/testcondition.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -791,25 +791,25 @@ class TestCondition : public TestFixture {
791791
" a++;\n"
792792
"}");
793793

794-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 3, the comparison x != 4 is always true.\n", errout.str());
794+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 3', the comparison 'x != 4' is always true.\n", errout.str());
795795

796796
check("void f(int x) {\n"
797797
" if ((x!=4) && (x==3))\n"
798798
" a++;\n"
799799
"}");
800-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 3, the comparison x != 4 is always true.\n", errout.str());
800+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 3', the comparison 'x != 4' is always true.\n", errout.str());
801801

802802
check("void f(int x) {\n"
803803
" if ((x==3) || (x!=4))\n"
804804
" a++;\n"
805805
"}");
806-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 3, the comparison x != 4 is always true.\n", errout.str());
806+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 3', the comparison 'x != 4' is always true.\n", errout.str());
807807

808808
check("void f(int x) {\n"
809809
" if ((x!=4) || (x==3))\n"
810810
" a++;\n"
811811
"}");
812-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 3, the comparison x != 4 is always true.\n", errout.str());
812+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 3', the comparison 'x != 4' is always true.\n", errout.str());
813813

814814
check("void f(int x) {\n"
815815
" if ((x==3) && (x!=3))\n"
@@ -839,7 +839,7 @@ class TestCondition : public TestFixture {
839839
" if (x > 5 && x == 6)\n"
840840
" a++;\n"
841841
"}");
842-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 6, the comparison x > 5 is always true.\n", errout.str());
842+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 6', the comparison 'x > 5' is always true.\n", errout.str());
843843

844844
// #3419
845845
check("void f() {\n"
@@ -948,7 +948,7 @@ class TestCondition : public TestFixture {
948948
" a++;\n"
949949
"}\n"
950950
);
951-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x > 5, the comparison x != 1 is always true.\n", errout.str());
951+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 5', the comparison 'x != 1' is always true.\n", errout.str());
952952

953953
check("void f(int x) {\n"
954954
" if (x > 5 && x != 6)\n"
@@ -962,7 +962,7 @@ class TestCondition : public TestFixture {
962962
" a++;\n"
963963
"}\n"
964964
);
965-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x > 5, the comparison x != 1 is always true.\n", errout.str());
965+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 5', the comparison 'x != 1' is always true.\n", errout.str());
966966

967967
check("void f(int x) {\n"
968968
" if ((x > 5) && (x != 6))\n"
@@ -977,32 +977,32 @@ class TestCondition : public TestFixture {
977977
" d = x >= 3 || x == 4;\n"
978978
" e = x <= 5 || x == 4;\n"
979979
"}");
980-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x == 4, the comparison x > 3 is always true.\n"
981-
"[test.cpp:3]: (style) Redundant condition: If x == 4, the comparison x < 5 is always true.\n"
982-
"[test.cpp:4]: (style) Redundant condition: If x == 4, the comparison x >= 3 is always true.\n"
983-
"[test.cpp:5]: (style) Redundant condition: If x == 4, the comparison x <= 5 is always true.\n", errout.str());
980+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x == 4', the comparison 'x > 3' is always true.\n"
981+
"[test.cpp:3]: (style) Redundant condition: If 'x == 4', the comparison 'x < 5' is always true.\n"
982+
"[test.cpp:4]: (style) Redundant condition: If 'x == 4', the comparison 'x >= 3' is always true.\n"
983+
"[test.cpp:5]: (style) Redundant condition: If 'x == 4', the comparison 'x <= 5' is always true.\n", errout.str());
984984

985985
check("void f(int x, bool& b) {\n"
986986
" b = x > 5 || x != 1;\n"
987987
" c = x < 1 || x != 3;\n"
988988
" d = x >= 5 || x != 1;\n"
989989
" e = x <= 1 || x != 3;\n"
990990
"}");
991-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x > 5, the comparison x != 1 is always true.\n"
992-
"[test.cpp:3]: (style) Redundant condition: If x < 1, the comparison x != 3 is always true.\n"
993-
"[test.cpp:4]: (style) Redundant condition: If x >= 5, the comparison x != 1 is always true.\n"
994-
"[test.cpp:5]: (style) Redundant condition: If x <= 1, the comparison x != 3 is always true.\n", errout.str());
991+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 5', the comparison 'x != 1' is always true.\n"
992+
"[test.cpp:3]: (style) Redundant condition: If 'x < 1', the comparison 'x != 3' is always true.\n"
993+
"[test.cpp:4]: (style) Redundant condition: If 'x >= 5', the comparison 'x != 1' is always true.\n"
994+
"[test.cpp:5]: (style) Redundant condition: If 'x <= 1', the comparison 'x != 3' is always true.\n", errout.str());
995995

996996
check("void f(int x, bool& b) {\n"
997997
" b = x > 6 && x > 5;\n"
998998
" c = x > 5 || x > 6;\n"
999999
" d = x < 6 && x < 5;\n"
10001000
" e = x < 5 || x < 6;\n"
10011001
"}");
1002-
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If x > 6, the comparison x > 5 is always true.\n"
1003-
"[test.cpp:3]: (style) Redundant condition: If x > 6, the comparison x > 5 is always true.\n"
1004-
"[test.cpp:4]: (style) Redundant condition: If x < 5, the comparison x < 6 is always true.\n"
1005-
"[test.cpp:5]: (style) Redundant condition: If x < 5, the comparison x < 6 is always true.\n", errout.str());
1002+
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 6', the comparison 'x > 5' is always true.\n"
1003+
"[test.cpp:3]: (style) Redundant condition: If 'x > 6', the comparison 'x > 5' is always true.\n"
1004+
"[test.cpp:4]: (style) Redundant condition: If 'x < 5', the comparison 'x < 6' is always true.\n"
1005+
"[test.cpp:5]: (style) Redundant condition: If 'x < 5', the comparison 'x < 6' is always true.\n", errout.str());
10061006
}
10071007

10081008
void incorrectLogicOp_condSwapping() {
@@ -1500,7 +1500,7 @@ class TestCondition : public TestFixture {
15001500
#ifdef _MSC_VER
15011501
ASSERT_EQUALS("", errout.str());
15021502
#else
1503-
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (style) Redundant condition: If init == 9894494448401390090, the comparison init == 9965707617509186058 is always true.\n", errout.str());
1503+
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (style) Redundant condition: If 'init == 9894494448401390090', the comparison 'init == 9965707617509186058' is always true.\n", errout.str());
15041504
#endif
15051505
}
15061506

0 commit comments

Comments
 (0)