22#include < string>
33
44// Global variables for testing
5- std::uint32_t g1 ;
6- std::int32_t g2 ;
7- std::uint8_t g3 ;
8- std::int8_t g4 ;
9- std::uint16_t g5 ;
10- std::int16_t g6 ;
11- std::uint64_t g7 ;
12- std::int64_t g8 ;
13- float g9 ;
14- double g10 ;
5+ std::uint32_t u32 ;
6+ std::int32_t s32 ;
7+ std::uint8_t u8 ;
8+ std::int8_t s8 ;
9+ std::uint16_t u16 ;
10+ std::int16_t s16 ;
11+ std::uint64_t u64 ;
12+ std::int64_t s64 ;
13+ float f ;
14+ double d ;
1515
1616// Test basic constant assignments
1717void test_constant_assignments () {
18- g1 = 1 ; // COMPLIANT
19- g2 = 4u * 2u ; // COMPLIANT
20- g3 = 3u ; // COMPLIANT
21- g3 = 300u ; // NON_COMPLIANT
22- g9 = 1 ; // COMPLIANT
23- g9 = 9999999999 ; // COMPLIANT
24- g10 = 0 .0f ; // NON_COMPLIANT
25- g9 = 0 .0f ; // COMPLIANT
18+ u32 = 1 ; // COMPLIANT
19+ s32 = 4u * 2u ; // COMPLIANT
20+ u8 = 3u ; // COMPLIANT
21+ u8 = 300u ; // NON_COMPLIANT
22+ f = 1 ; // COMPLIANT
23+ f = 9999999999 ; // COMPLIANT
24+ d = 0 .0f ; // NON_COMPLIANT
25+ f = 0 .0f ; // COMPLIANT
2626}
2727
2828// Test signedness violations
2929void test_signedness_violations () {
30- g3 = g4 ; // NON_COMPLIANT
31- g4 = g3 ; // NON_COMPLIANT
30+ u8 = s8 ; // NON_COMPLIANT
31+ s8 = u8 ; // NON_COMPLIANT
3232}
3333
3434// Test size violations
3535void test_size_violations () {
36- g3 = g5 ; // NON_COMPLIANT
37- g5 = g7 ; // NON_COMPLIANT
36+ u8 = u16 ; // NON_COMPLIANT
37+ u16 = u64 ; // NON_COMPLIANT
3838}
3939
4040// Test type category violations
4141void test_type_category_violations () {
42- g9 = g2 ; // NON_COMPLIANT
43- g2 = g9 ; // NON_COMPLIANT
42+ f = s32 ; // NON_COMPLIANT
43+ s32 = f ; // NON_COMPLIANT
4444}
4545
4646// Test widening of id-expressions
4747void test_widening_id_expressions () {
48- g1 = g3 ; // COMPLIANT
49- g8 = g4 ; // COMPLIANT
50- g7 = g5 ; // COMPLIANT
48+ u32 = u8 ; // COMPLIANT
49+ s64 = s8 ; // COMPLIANT
50+ u64 = u16 ; // COMPLIANT
5151}
5252
5353// Test expression results
5454void test_expression_results () {
55- g3 = g3 + g3 ; // NON_COMPLIANT
56- std::int16_t l1 = g4 + g4 ; // NON_COMPLIANT
55+ u8 = u8 + u8 ; // NON_COMPLIANT
56+ std::int16_t l1 = s8 + s8 ; // NON_COMPLIANT
5757}
5858
5959// Test bit-fields
@@ -65,8 +65,8 @@ void test_bitfields() {
6565 S l1;
6666 l1.m1 = 2 ; // COMPLIANT
6767 l1.m1 = 32u ; // NON_COMPLIANT
68- l1.m1 = g3 ; // COMPLIANT
69- l1.m1 = g5 ; // NON_COMPLIANT
68+ l1.m1 = u8 ; // COMPLIANT
69+ l1.m1 = u16 ; // NON_COMPLIANT
7070}
7171
7272// Test enums
@@ -76,22 +76,22 @@ enum States { enabled, disabled };
7676
7777void test_enums () {
7878 Colour l1 = red;
79- g3 = red; // COMPLIANT
80- g1 = red; // COMPLIANT
81- g3 = l1; // NON_COMPLIANT
82- g1 = l1; // COMPLIANT
83- g3 = enabled; // COMPLIANT - enabled is not numeric
79+ u8 = red; // COMPLIANT
80+ u32 = red; // COMPLIANT
81+ u8 = l1; // NON_COMPLIANT
82+ u32 = l1; // COMPLIANT
83+ u8 = enabled; // COMPLIANT - enabled is not numeric
8484}
8585
8686// Test function parameters - non-overload-independent
8787void f1 (std::int64_t l1) {}
8888void f2 (std::int32_t l1) {}
8989
9090void test_function_parameters_non_overload_independent () {
91- f1 (g2 ); // NON_COMPLIANT
92- f1 (g8 ); // COMPLIANT
93- f2 (g2 ); // COMPLIANT
94- f2 (g8 ); // NON_COMPLIANT
91+ f1 (s32 ); // NON_COMPLIANT
92+ f1 (s64 ); // COMPLIANT
93+ f2 (s32 ); // COMPLIANT
94+ f2 (s64 ); // NON_COMPLIANT
9595 int l1 = 42 ;
9696 f2 (l1); // NON_COMPLIANT - needs to be the same type as the parameter
9797 signed int l2 = 42 ;
@@ -105,9 +105,9 @@ void f3(std::int64_t l1) {}
105105void f3 (std::int32_t l1) {}
106106
107107void test_overloaded_functions () {
108- f3 (g2 ); // COMPLIANT
109- f3 (g4 ); // NON_COMPLIANT
110- f3 (g8 ); // COMPLIANT
108+ f3 (s32 ); // COMPLIANT
109+ f3 (s8 ); // NON_COMPLIANT
110+ f3 (s64 ); // COMPLIANT
111111}
112112
113113// Test function pointers - always "overload-independent"
@@ -123,8 +123,8 @@ void test_function_pointers() {
123123void f5 (const char *l1, ...) {}
124124
125125void test_variadic_functions () {
126- f5 (" test" , g3 ); // NON_COMPLIANT - will be promoted to `int`
127- f5 (" test" , g2 ); // COMPLIANT - already `int`, no promotion needed
126+ f5 (" test" , u8 ); // NON_COMPLIANT - will be promoted to `int`
127+ f5 (" test" , s32 ); // COMPLIANT - already `int`, no promotion needed
128128}
129129
130130// Test member function calls - not overload-independent
@@ -135,11 +135,11 @@ struct A {
135135};
136136
137137void A::f7 () {
138- f6 (g1 , " answer" ); // NON_COMPLIANT - extensible, could call a global
138+ f6 (u32 , " answer" ); // NON_COMPLIANT - extensible, could call a global
139139 // function instead - e.g. `void f6(std::uint32_t l1,
140140 // std::string l2)`
141- this ->f6 (g1 , " answer" ); // COMPLIANT
142- this ->f6 (g1 , 42 ); // COMPLIANT
141+ this ->f6 (u32 , " answer" ); // COMPLIANT
142+ this ->f6 (u32 , 42 ); // COMPLIANT
143143}
144144
145145void test_member_function_overload_independent () {
@@ -169,8 +169,8 @@ struct MyInt {
169169void f9 (MyInt l1) {}
170170
171171void test_constructor_exception () {
172- f9 (MyInt{g4 }); // COMPLIANT
173- MyInt l1{g4 }; // COMPLIANT
172+ f9 (MyInt{s8 }); // COMPLIANT
173+ MyInt l1{s8 }; // COMPLIANT
174174}
175175
176176// Test template functions - not overload-independent
@@ -202,7 +202,7 @@ std::int32_t f12(std::int8_t l1) {
202202
203203// Test switch cases
204204void test_switch_cases () {
205- switch (g4 ) {
205+ switch (s8 ) {
206206 case 1 : // COMPLIANT
207207 break ;
208208 case 0x7F : // COMPLIANT
0 commit comments