@@ -9,6 +9,7 @@ std::uint8_t g4 = 20;
99std::int16_t g5 = 100 ;
1010std::int32_t g6 = 200 ;
1111bool g7 = true ;
12+ std::int32_t g8[5 ] = {1 , 2 , 3 , 4 , 5 };
1213
1314// Function declarations
1415std::int32_t f1 ();
@@ -30,6 +31,12 @@ class TestClassImplicit {
3031 operator bool () const { return m1 < 0 ; } // Implicit conversion
3132};
3233
34+ // Class with member function pointer
35+ class TestClassMemberFunc {
36+ public:
37+ void memberFunc () {}
38+ };
39+
3340// Bit-field struct for exception #3
3441struct BitFieldStruct {
3542 unsigned int m1 : 1 ;
@@ -96,12 +103,32 @@ void test_while_loops() {
96103 }
97104}
98105
106+ void test_do_while_loops () {
107+ std::int32_t l1 = 5 ;
108+ bool l2 = true ;
109+
110+ do {
111+ --l1;
112+ } while (l1); // NON_COMPLIANT
113+
114+ do {
115+ --l1;
116+ } while (l2); // COMPLIANT
117+
118+ do {
119+ --l1;
120+ } while (l1 > 0 ); // COMPLIANT
121+ }
122+
99123void test_pointer_conversions () {
100124 if (f3 ()) { // COMPLIANT - exception #2
101125 }
102126
103127 bool l1 = f3 (); // NON_COMPLIANT
104128 bool l2 = f3 () != nullptr ; // COMPLIANT
129+
130+ if (nullptr ) { // NON_COMPLIANT
131+ }
105132}
106133
107134void test_assignment_to_bool () {
@@ -111,7 +138,7 @@ void test_assignment_to_bool() {
111138 bool l4 = g7; // COMPLIANT
112139}
113140
114- void test_class_with_explicit_bool_operator () {
141+ void test_classes_with_bool_operators () {
115142 TestClassExplicit l1;
116143
117144 bool l2 = static_cast <bool >(l1); // COMPLIANT - exception #1
@@ -142,4 +169,46 @@ void test_scoped_enum_conversion() {
142169 Status l1 = Status::ACTIVE;
143170
144171 bool l2 = (l1 == Status::ACTIVE); // COMPLIANT
172+ }
173+
174+ void test_floating_point_conversion () {
175+ float l1 = 3 .14f ;
176+ double l2 = 2.71 ;
177+ long double l3 = 1 .41L ;
178+
179+ bool l4 = l1; // NON_COMPLIANT
180+ bool l5 = l2; // NON_COMPLIANT
181+ bool l6 = l3; // NON_COMPLIANT
182+ if (l1) { // NON_COMPLIANT
183+ }
184+ if (l2) { // NON_COMPLIANT
185+ }
186+ if (l3) { // NON_COMPLIANT
187+ }
188+ bool l7 = (l1 > 0 .0f ); // COMPLIANT
189+ bool l8 = (l2 != 0.0 ); // COMPLIANT
190+ }
191+
192+ void test_array_conversion () {
193+ std::int32_t l1[5 ] = {1 , 2 , 3 , 4 , 5 };
194+
195+ if (l1) { // NON_COMPLIANT
196+ }
197+ if (g8) { // NON_COMPLIANT
198+ }
199+ bool l2 = l1; // NON_COMPLIANT
200+ bool l3 = (l1 != nullptr ); // COMPLIANT
201+ }
202+
203+ void test_member_function_pointer_conversion () {
204+ void (TestClassMemberFunc::*l1)() = &TestClassMemberFunc::memberFunc;
205+ void (TestClassMemberFunc::*l2)() = nullptr ;
206+
207+ if (l1) { // COMPLIANT - exception #2
208+ }
209+ if (l2) { // COMPLIANT - exception #2
210+ }
211+ bool l3 = l1; // NON_COMPLIANT
212+ bool l4 = l2; // NON_COMPLIANT
213+ bool l5 = (l1 != nullptr ); // COMPLIANT
145214}
0 commit comments