2
2
#include < string>
3
3
4
4
// 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 ;
15
15
16
16
// Test basic constant assignments
17
17
void 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
26
26
}
27
27
28
28
// Test signedness violations
29
29
void test_signedness_violations () {
30
- g3 = g4 ; // NON_COMPLIANT
31
- g4 = g3 ; // NON_COMPLIANT
30
+ u8 = s8 ; // NON_COMPLIANT
31
+ s8 = u8 ; // NON_COMPLIANT
32
32
}
33
33
34
34
// Test size violations
35
35
void test_size_violations () {
36
- g3 = g5 ; // NON_COMPLIANT
37
- g5 = g7 ; // NON_COMPLIANT
36
+ u8 = u16 ; // NON_COMPLIANT
37
+ u16 = u64 ; // NON_COMPLIANT
38
38
}
39
39
40
40
// Test type category violations
41
41
void test_type_category_violations () {
42
- g9 = g2 ; // NON_COMPLIANT
43
- g2 = g9 ; // NON_COMPLIANT
42
+ f = s32 ; // NON_COMPLIANT
43
+ s32 = f ; // NON_COMPLIANT
44
44
}
45
45
46
46
// Test widening of id-expressions
47
47
void 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
51
51
}
52
52
53
53
// Test expression results
54
54
void 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
57
57
}
58
58
59
59
// Test bit-fields
@@ -65,8 +65,8 @@ void test_bitfields() {
65
65
S l1;
66
66
l1.m1 = 2 ; // COMPLIANT
67
67
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
70
70
}
71
71
72
72
// Test enums
@@ -76,22 +76,22 @@ enum States { enabled, disabled };
76
76
77
77
void test_enums () {
78
78
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
84
84
}
85
85
86
86
// Test function parameters - non-overload-independent
87
87
void f1 (std::int64_t l1) {}
88
88
void f2 (std::int32_t l1) {}
89
89
90
90
void 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
95
95
int l1 = 42 ;
96
96
f2 (l1); // NON_COMPLIANT - needs to be the same type as the parameter
97
97
signed int l2 = 42 ;
@@ -105,9 +105,9 @@ void f3(std::int64_t l1) {}
105
105
void f3 (std::int32_t l1) {}
106
106
107
107
void 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
111
111
}
112
112
113
113
// Test function pointers - always "overload-independent"
@@ -123,8 +123,8 @@ void test_function_pointers() {
123
123
void f5 (const char *l1, ...) {}
124
124
125
125
void 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
128
128
}
129
129
130
130
// Test member function calls - not overload-independent
@@ -135,11 +135,11 @@ struct A {
135
135
};
136
136
137
137
void A::f7 () {
138
- f6 (g1 , " answer" ); // NON_COMPLIANT - extensible, could call a global
138
+ f6 (u32 , " answer" ); // NON_COMPLIANT - extensible, could call a global
139
139
// function instead - e.g. `void f6(std::uint32_t l1,
140
140
// 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
143
143
}
144
144
145
145
void test_member_function_overload_independent () {
@@ -169,8 +169,8 @@ struct MyInt {
169
169
void f9 (MyInt l1) {}
170
170
171
171
void test_constructor_exception () {
172
- f9 (MyInt{g4 }); // COMPLIANT
173
- MyInt l1{g4 }; // COMPLIANT
172
+ f9 (MyInt{s8 }); // COMPLIANT
173
+ MyInt l1{s8 }; // COMPLIANT
174
174
}
175
175
176
176
// Test template functions - not overload-independent
@@ -202,7 +202,7 @@ std::int32_t f12(std::int8_t l1) {
202
202
203
203
// Test switch cases
204
204
void test_switch_cases () {
205
- switch (g4 ) {
205
+ switch (s8 ) {
206
206
case 1 : // COMPLIANT
207
207
break ;
208
208
case 0x7F : // COMPLIANT
0 commit comments