@@ -302,7 +302,8 @@ class TestOther : public TestFixture {
302302 TEST_CASE (knownPointerToBool);
303303 TEST_CASE (iterateByValue);
304304
305- TEST_CASE (alwaysTrueFloating);
305+ TEST_CASE (knownConditionFloating);
306+ TEST_CASE (knownConditionPrefixed);
306307 }
307308
308309#define check (...) check_(__FILE__, __LINE__, __VA_ARGS__)
@@ -12888,7 +12889,7 @@ class TestOther : public TestFixture {
1288812889 errout_str ());
1288912890 }
1289012891
12891- void alwaysTrueFloating ()
12892+ void knownConditionFloating ()
1289212893 {
1289312894 check (" void foo() {\n " // #11200
1289412895 " float f = 1.0;\n "
@@ -12905,9 +12906,16 @@ class TestOther : public TestFixture {
1290512906 " float f = 1.0;\n "
1290612907 " if (f > +1.0) {}\n "
1290712908 " }\n " );
12908- TODO_ASSERT_EQUALS (
12909+ ASSERT_EQUALS (
1290912910 " [test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f > +1.0' is always false.\n " ,
12910- " " ,
12911+ errout_str ());
12912+
12913+ check (" void foo() {\n "
12914+ " float f = 1.0;\n "
12915+ " if (f < +1.0) {}\n "
12916+ " }\n " );
12917+ ASSERT_EQUALS (
12918+ " [test.cpp:2] -> [test.cpp:3]: (style) The comparison 'f < 1.0' is always false.\n " ,
1291112919 errout_str ());
1291212920
1291312921 check (" void foo() {\n " // #11200
@@ -12925,9 +12933,16 @@ class TestOther : public TestFixture {
1292512933 " float pf = +1.0;\n "
1292612934 " if (pf > +1.0) {}\n "
1292712935 " }\n " );
12928- TODO_ASSERT_EQUALS (
12936+ ASSERT_EQUALS (
1292912937 " [test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf > +1.0' is always false.\n " ,
12930- " " ,
12938+ errout_str ());
12939+
12940+ check (" void foo() {\n "
12941+ " float pf = +1.0;\n "
12942+ " if (pf < +1.0) {}\n "
12943+ " }\n " );
12944+ ASSERT_EQUALS (
12945+ " [test.cpp:2] -> [test.cpp:3]: (style) The comparison 'pf < 1.0' is always false.\n " ,
1293112946 errout_str ());
1293212947
1293312948 check (" void foo() {\n " // #11200
@@ -12941,7 +12956,7 @@ class TestOther : public TestFixture {
1294112956 " [test.cpp:2] -> [test.cpp:4]: (style) The comparison 'nf > -1.0' is always false.\n " ,
1294212957 errout_str ());
1294312958
12944- check (" void foo() {\n " // #13506
12959+ check (" void foo() {\n " // #13508
1294512960 " float nf = -1.0;\n "
1294612961 " if (nf > +1.0) {}\n "
1294712962 " }\n " );
@@ -12984,6 +12999,25 @@ class TestOther : public TestFixture {
1298412999 " " ,
1298513000 errout_str ());
1298613001 }
13002+
13003+ void knownConditionPrefixed ()
13004+ {
13005+ check (" void foo() {\n "
13006+ " int i = 1;\n "
13007+ " if (i < +1) {}\n "
13008+ " }\n " );
13009+ ASSERT_EQUALS (
13010+ " [test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i < 1' is always false.\n " ,
13011+ errout_str ());
13012+
13013+ check (" void foo() {\n " // #13506
13014+ " int i = 1;\n "
13015+ " if (i > +1) {}\n "
13016+ " }\n " );
13017+ ASSERT_EQUALS (
13018+ " [test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i > +1' is always false.\n " ,
13019+ errout_str ());
13020+ }
1298713021};
1298813022
1298913023REGISTER_TEST (TestOther)
0 commit comments