@@ -124,6 +124,7 @@ class TestCondition : public TestFixture {
124124 TEST_CASE (knownConditionIncrementLoop); // #9808
125125 TEST_CASE (knownConditionAfterBailout); // #12526
126126 TEST_CASE (knownConditionIncDecOperator);
127+ TEST_CASE (knownConditionFloating);
127128 }
128129
129130#define check (...) check_(__FILE__, __LINE__, __VA_ARGS__)
@@ -4464,9 +4465,10 @@ class TestCondition : public TestFixture {
44644465 " float f = 9.9f;\n "
44654466 " if(f < 10) {}\n "
44664467 " }\n " );
4467- ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'i>9.9' is always true\n "
4468- " [test.cpp:5]: (style) Condition 'f<10' is always true\n " ,
4469- errout_str ());
4468+ ASSERT_EQUALS (
4469+ " [test.cpp:3]: (style) Condition 'i>9.9' is always true\n "
4470+ " [test.cpp:5]: (style) Condition 'f<10' is always true\n " ,
4471+ errout_str ());
44704472 check (" constexpr int f() {\n " // #11238
44714473 " return 1;\n "
44724474 " }\n "
@@ -5770,6 +5772,14 @@ class TestCondition : public TestFixture {
57705772 " if (other.mPA.cols > 0 && other.mPA.rows > 0)\n "
57715773 " ;\n "
57725774 " }" );
5775+ ASSERT_EQUALS (" " , errout_str ());
5776+
5777+ check (" void foo() {\n " // #11202
5778+ " float f = 0x1.4p+3;\n "
5779+ " if (f > 10.0) {}\n "
5780+ " if (f < 10.0) {}\n "
5781+ " }\n " );
5782+ ASSERT_EQUALS (" " , errout_str ());
57735783 }
57745784
57755785 void checkInvalidTestForOverflow () {
@@ -6229,6 +6239,122 @@ class TestCondition : public TestFixture {
62296239 " }\n " );
62306240 ASSERT_EQUALS (" " , errout_str ());
62316241 }
6242+
6243+ void knownConditionFloating () {
6244+ check (" void foo() {\n " // #11199
6245+ " float f = 1.0;\n "
6246+ " if (f > 1.0f) {}\n "
6247+ " }\n " );
6248+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'f>1.0f' is always false\n " , errout_str ());
6249+
6250+ check (" void foo() {\n " // #11199
6251+ " float f = 1.0;\n "
6252+ " if (f > 1.0L) {}\n "
6253+ " }\n " );
6254+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'f>1.0L' is always false\n " , errout_str ());
6255+
6256+ check (" void foo() {\n " // #11199
6257+ " float f = 1.0f;\n "
6258+ " if (f > 1.0) {}\n "
6259+ " }\n " );
6260+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'f>1.0' is always false\n " , errout_str ());
6261+
6262+ check (" void foo() {\n " // #11199
6263+ " float f = 1.0f;\n "
6264+ " if (f > 1.0L) {}\n "
6265+ " }\n " );
6266+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'f>1.0L' is always false\n " , errout_str ());
6267+
6268+ check (" void foo() {\n " // #11199
6269+ " float f = 1.0L;\n "
6270+ " if (f > 1.0) {}\n "
6271+ " }\n " );
6272+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'f>1.0' is always false\n " , errout_str ());
6273+
6274+ check (" void foo() {\n " // #11199
6275+ " float f = 1.0L;\n "
6276+ " if (f > 1.0f) {}\n "
6277+ " }\n " );
6278+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'f>1.0f' is always false\n " , errout_str ());
6279+
6280+ check (" void foo() {\n " // #11201
6281+ " float f = 0x1.4p+3;\n " // hex fraction 1.4 (decimal 1.25) scaled by 2^3, that is 10.0
6282+ " if (f > 9.9) {}\n "
6283+ " if (f < 9.9) {}\n "
6284+ " }\n " );
6285+ ASSERT_EQUALS (
6286+ " [test.cpp:3]: (style) Condition 'f>9.9' is always true\n "
6287+ " [test.cpp:4]: (style) Condition 'f<9.9' is always false\n " ,
6288+ errout_str ());
6289+
6290+ check (" void foo() {\n " // #12330
6291+ " double d = 1.0;\n "
6292+ " if (d < 0.0) {}\n "
6293+ " }\n " );
6294+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'd<0.0' is always false\n " , errout_str ());
6295+
6296+ check (" void foo() {\n " // #12330
6297+ " long double ld = 1.0;\n "
6298+ " if (ld < 0.0) {}\n "
6299+ " }\n " );
6300+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'ld<0.0' is always false\n " , errout_str ());
6301+
6302+ check (" void foo() {\n " // #12330
6303+ " float f = 1.0;\n "
6304+ " if (f < 0.0) {}\n "
6305+ " }\n " );
6306+ ASSERT_EQUALS (" [test.cpp:3]: (style) Condition 'f<0.0' is always false\n " , errout_str ());
6307+
6308+ check (" void foo() {\n " // #12774
6309+ " float f = 1.0f;\n "
6310+ " if (f > 1.01f) {}\n "
6311+ " }\n " );
6312+ ASSERT_EQUALS (
6313+ " [test.cpp:3]: (style) Condition 'f>1.01f' is always false\n " ,
6314+ errout_str ());
6315+
6316+ check (" void foo() {\n " // #12774
6317+ " float f = 1.0;\n "
6318+ " if (f > 1.01) {}\n "
6319+ " }\n " );
6320+ ASSERT_EQUALS (
6321+ " [test.cpp:3]: (style) Condition 'f>1.01' is always false\n " ,
6322+ errout_str ());
6323+
6324+ check (" void foo() {\n "
6325+ " float f = 1.0f;\n "
6326+ " if (f > 1) {}\n "
6327+ " }\n " );
6328+ ASSERT_EQUALS (
6329+ " [test.cpp:3]: (style) Condition 'f>1' is always false\n " ,
6330+ errout_str ());
6331+
6332+ check (" void foo() {\n " // #13508
6333+ " float f = 1.0f;\n "
6334+ " if (f > 1.00f) {}\n "
6335+ " }\n " );
6336+ TODO_ASSERT_EQUALS (
6337+ " [test.cpp:3]: (style) Condition 'f>1.00f' is always false\n " ,
6338+ " " ,
6339+ errout_str ());
6340+
6341+ check (" void foo() {\n "
6342+ " float f = 1.0;\n "
6343+ " if (f > 1) {}\n "
6344+ " }\n " );
6345+ ASSERT_EQUALS (
6346+ " [test.cpp:3]: (style) Condition 'f>1' is always false\n " ,
6347+ errout_str ());
6348+
6349+ check (" void foo() {\n " // #13508
6350+ " float f = 1.0;\n "
6351+ " if (f > 1.00) {}\n "
6352+ " }\n " );
6353+ TODO_ASSERT_EQUALS (
6354+ " [test.cpp:3]: (style) Condition 'f>1.00' is always false\n " ,
6355+ " " ,
6356+ errout_str ());
6357+ }
62326358};
62336359
62346360REGISTER_TEST (TestCondition)
0 commit comments