Skip to content

Commit 229705f

Browse files
committed
Rule 7.0.6: Update test with better variable names
1 parent a2c9912 commit 229705f

File tree

2 files changed

+64
-64
lines changed

2 files changed

+64
-64
lines changed
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
| test.cpp:21:8:21:11 | 300 | Assignment between incompatible numeric types from 'unsigned int' to 'uint8_t'. |
2-
| test.cpp:24:9:24:12 | 0.0 | Assignment between incompatible numeric types from 'float' to 'double'. |
3-
| test.cpp:30:8:30:9 | g4 | Assignment between incompatible numeric types from 'int8_t' to 'uint8_t'. |
4-
| test.cpp:31:8:31:9 | g3 | Assignment between incompatible numeric types from 'uint8_t' to 'int8_t'. |
5-
| test.cpp:36:8:36:9 | g5 | Assignment between incompatible numeric types from 'uint16_t' to 'uint8_t'. |
6-
| test.cpp:37:8:37:9 | g7 | Assignment between incompatible numeric types from 'uint64_t' to 'uint16_t'. |
7-
| test.cpp:42:8:42:9 | g2 | Assignment between incompatible numeric types from 'int32_t' to 'float'. |
8-
| test.cpp:43:8:43:9 | g9 | Assignment between incompatible numeric types from 'float' to 'int32_t'. |
2+
| test.cpp:24:7:24:10 | 0.0 | Assignment between incompatible numeric types from 'float' to 'double'. |
3+
| test.cpp:30:8:30:9 | s8 | Assignment between incompatible numeric types from 'int8_t' to 'uint8_t'. |
4+
| test.cpp:31:8:31:9 | u8 | Assignment between incompatible numeric types from 'uint8_t' to 'int8_t'. |
5+
| test.cpp:36:8:36:10 | u16 | Assignment between incompatible numeric types from 'uint16_t' to 'uint8_t'. |
6+
| test.cpp:37:9:37:11 | u64 | Assignment between incompatible numeric types from 'uint64_t' to 'uint16_t'. |
7+
| test.cpp:42:7:42:9 | s32 | Assignment between incompatible numeric types from 'int32_t' to 'float'. |
8+
| test.cpp:43:9:43:9 | f | Assignment between incompatible numeric types from 'float' to 'int32_t'. |
99
| test.cpp:55:8:55:14 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint8_t'. |
1010
| test.cpp:56:21:56:27 | ... + ... | Assignment between incompatible numeric types from 'int' to 'int16_t'. |
1111
| test.cpp:67:11:67:13 | 32 | Assignment between incompatible numeric types from 'uint32_t' to 'unsigned char'. |
12-
| test.cpp:69:11:69:12 | g5 | Assignment between incompatible numeric types from 'uint16_t' to 'unsigned char'. |
12+
| test.cpp:69:11:69:13 | u16 | Assignment between incompatible numeric types from 'uint16_t' to 'unsigned char'. |
1313
| test.cpp:81:8:81:9 | l1 | Assignment between incompatible numeric types from 'Colour' to 'uint8_t'. |
14-
| test.cpp:91:6:91:7 | g2 | Assignment between incompatible numeric types from 'int32_t' to 'int64_t'. |
15-
| test.cpp:94:6:94:7 | g8 | Assignment between incompatible numeric types from 'int64_t' to 'int32_t'. |
14+
| test.cpp:91:6:91:8 | s32 | Assignment between incompatible numeric types from 'int32_t' to 'int64_t'. |
15+
| test.cpp:94:6:94:8 | s64 | Assignment between incompatible numeric types from 'int64_t' to 'int32_t'. |
1616
| test.cpp:96:6:96:7 | l1 | Assignment between incompatible numeric types from 'int' to 'int32_t'. |
17-
| test.cpp:109:6:109:7 | g4 | Assignment between incompatible numeric types from 'int8_t' to 'int32_t'. |
17+
| test.cpp:109:6:109:7 | s8 | Assignment between incompatible numeric types from 'int8_t' to 'int32_t'. |
1818
| test.cpp:118:6:118:6 | 2 | Assignment between incompatible numeric types from 'int' to 'long'. |
19-
| test.cpp:126:14:126:15 | g3 | Assignment between incompatible numeric types from 'uint8_t' to 'int'. |
20-
| test.cpp:138:6:138:7 | g1 | Assignment between incompatible numeric types from 'uint32_t' to 'size_t'. |
19+
| test.cpp:126:14:126:15 | u8 | Assignment between incompatible numeric types from 'uint8_t' to 'int'. |
20+
| test.cpp:138:6:138:8 | u32 | Assignment between incompatible numeric types from 'uint32_t' to 'size_t'. |
2121
| test.cpp:160:9:160:10 | 42 | Assignment between incompatible numeric types from 'int' to 'long'. |
2222
| test.cpp:189:23:189:24 | 42 | Assignment between incompatible numeric types from 'int' to 'unsigned long'. |
2323
| test.cpp:199:19:199:25 | ... + ... | Assignment between incompatible numeric types from 'int' to 'int16_t'. |

cpp/misra/test/rules/RULE-7-0-6/test.cpp

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,58 @@
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
1717
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
2626
}
2727

2828
// Test signedness violations
2929
void 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
3535
void 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
4141
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
4444
}
4545

4646
// Test widening of id-expressions
4747
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
5151
}
5252

5353
// Test expression results
5454
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
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

7777
void 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
8787
void f1(std::int64_t l1) {}
8888
void f2(std::int32_t l1) {}
8989

9090
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
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) {}
105105
void f3(std::int32_t l1) {}
106106

107107
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
111111
}
112112

113113
// Test function pointers - always "overload-independent"
@@ -123,8 +123,8 @@ void test_function_pointers() {
123123
void f5(const char *l1, ...) {}
124124

125125
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
128128
}
129129

130130
// Test member function calls - not overload-independent
@@ -135,11 +135,11 @@ struct A {
135135
};
136136

137137
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
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

145145
void test_member_function_overload_independent() {
@@ -169,8 +169,8 @@ struct MyInt {
169169
void f9(MyInt l1) {}
170170

171171
void 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
204204
void test_switch_cases() {
205-
switch (g4) {
205+
switch (s8) {
206206
case 1: // COMPLIANT
207207
break;
208208
case 0x7F: // COMPLIANT

0 commit comments

Comments
 (0)