@@ -53,6 +53,7 @@ class TestBool : public TestFixture {
5353 TEST_CASE (comparisonOfBoolWithInt5);
5454 TEST_CASE (comparisonOfBoolWithInt6); // #4224 - integer is casted to bool
5555 TEST_CASE (comparisonOfBoolWithInt7); // #4846 - (!x == true)
56+ TEST_CASE (comparisonOfBoolWithInt8); // #9165
5657
5758 TEST_CASE (checkComparisonOfFuncReturningBool1);
5859 TEST_CASE (checkComparisonOfFuncReturningBool2);
@@ -995,6 +996,50 @@ class TestBool : public TestFixture {
995996 ASSERT_EQUALS (" " , errout.str ());
996997 }
997998
999+ void comparisonOfBoolWithInt8 () { // #9165
1000+ check (" bool Fun();\n "
1001+ " void Test(bool expectedResult) {\n "
1002+ " auto res = Fun();\n "
1003+ " if (expectedResult == res)\n "
1004+ " throw 2;\n "
1005+ " }" );
1006+ ASSERT_EQUALS (" " , errout.str ());
1007+
1008+ check (" int Fun();\n "
1009+ " void Test(bool expectedResult) {\n "
1010+ " auto res = Fun();\n "
1011+ " if (expectedResult == res)\n "
1012+ " throw 2;\n "
1013+ " }" );
1014+ ASSERT_EQUALS (" [test.cpp:4]: (warning) Comparison of a boolean expression with an integer.\n " , errout.str ());
1015+
1016+ check (" bool Fun();\n "
1017+ " void Test(bool expectedResult) {\n "
1018+ " auto res = Fun();\n "
1019+ " if (5 + expectedResult == res)\n "
1020+ " throw 2;\n "
1021+ " }" );
1022+ ASSERT_EQUALS (" [test.cpp:4]: (warning) Comparison of a boolean expression with an integer.\n " , errout.str ());
1023+
1024+ fprintf (stderr, " last case\n " );
1025+ check (" int Fun();\n "
1026+ " void Test(bool expectedResult) {\n "
1027+ " auto res = Fun();\n "
1028+ " if (5 + expectedResult == res)\n "
1029+ " throw 2;\n "
1030+ " }" );
1031+ ASSERT_EQUALS (" " , errout.str ());
1032+
1033+ check (" int Fun();\n "
1034+ " void Test(bool expectedResult) {\n "
1035+ " auto res = Fun();\n "
1036+ " if (expectedResult == res + 5)\n "
1037+ " throw 2;\n "
1038+ " }" );
1039+ ASSERT_EQUALS (" [test.cpp:4]: (warning) Comparison of a boolean expression with an integer.\n " , errout.str ());
1040+ }
1041+
1042+
9981043 void pointerArithBool1 () { // #5126
9991044 check (" void f(char *p) {\n "
10001045 " if (p+1){}\n "
0 commit comments