@@ -36,7 +36,7 @@ class TestDivision : public TestFixture
3636 { }
3737
3838private:
39- void check (const char code[])
39+ void check (const char code[], bool style = true , bool all = true )
4040 {
4141 // Tokenize..
4242 Tokenizer tokenizer;
@@ -47,8 +47,8 @@ class TestDivision : public TestFixture
4747 errout.str (" " );
4848
4949 Settings settings;
50- settings._showAll = true ;
51- settings._checkCodingStyle = true ;
50+ settings._showAll = all ;
51+ settings._checkCodingStyle = style ;
5252
5353 // Check for unsigned divisions..
5454 CheckOther checkOther (&tokenizer, &settings, this );
@@ -64,6 +64,7 @@ class TestDivision : public TestFixture
6464 TEST_CASE (division5);
6565 TEST_CASE (division6);
6666 TEST_CASE (division7);
67+ TEST_CASE (division8);
6768 }
6869
6970 void division1 ()
@@ -74,7 +75,7 @@ class TestDivision : public TestFixture
7475 " unsigned int uvar = 2;\n "
7576 " return ivar / uvar;\n "
7677 " }\n " );
77- ASSERT_EQUALS (" [test.cpp:5]: (possible style) Warning: Division with signed and unsigned operators\n " , errout.str ());
78+ ASSERT_EQUALS (" [test.cpp:5]: (possible style) Division with signed and unsigned operators\n " , errout.str ());
7879 }
7980
8081 void division2 ()
@@ -85,7 +86,7 @@ class TestDivision : public TestFixture
8586 " unsigned int uvar = 2;\n "
8687 " return uvar / ivar;\n "
8788 " }\n " );
88- ASSERT_EQUALS (" [test.cpp:5]: (possible style) Warning: Division with signed and unsigned operators\n " , errout.str ());
89+ ASSERT_EQUALS (" [test.cpp:5]: (possible style) Division with signed and unsigned operators\n " , errout.str ());
8990 }
9091
9192 void division3 ()
@@ -98,7 +99,7 @@ class TestDivision : public TestFixture
9899 " u32 uvar = 2;\n "
99100 " return uvar / ivar;\n "
100101 " }\n " );
101- ASSERT_EQUALS (" [test.cpp:7]: (possible style) Warning: Division with signed and unsigned operators\n " , errout.str ());
102+ ASSERT_EQUALS (" [test.cpp:7]: (possible style) Division with signed and unsigned operators\n " , errout.str ());
102103 }
103104
104105 void division4 ()
@@ -146,6 +147,36 @@ class TestDivision : public TestFixture
146147 );
147148 ASSERT_EQUALS (" [test.cpp:4]: (error) Unsigned division. The result will be wrong.\n " , errout.str ());
148149 }
150+
151+ void division8 ()
152+ {
153+ check (" void foo(int b)\n "
154+ " {\n "
155+ " if (b > 0)\n "
156+ " {\n "
157+ " unsigned int a;\n "
158+ " unsigned int c = a / b;\n "
159+ " }\n " , false , true );
160+ ASSERT_EQUALS (" " , errout.str ());
161+
162+ check (" void foo(int b)\n "
163+ " {\n "
164+ " if (b > 0)\n "
165+ " {\n "
166+ " unsigned int a;\n "
167+ " unsigned int c = a / b;\n "
168+ " }\n " , true , false );
169+ ASSERT_EQUALS (" " , errout.str ());
170+
171+ check (" void foo(int b)\n "
172+ " {\n "
173+ " if (b > 0)\n "
174+ " {\n "
175+ " unsigned int a;\n "
176+ " unsigned int c = a / b;\n "
177+ " }\n " , true , true );
178+ ASSERT_EQUALS (" [test.cpp:6]: (possible style) Division with signed and unsigned operators\n " , errout.str ());
179+ }
149180};
150181
151182REGISTER_TEST (TestDivision)
0 commit comments