File tree Expand file tree Collapse file tree 7 files changed +67
-8
lines changed
common/src/codingstandards/cpp Expand file tree Collapse file tree 7 files changed +67
-8
lines changed Original file line number Diff line number Diff line change 1- | test.cpp:11:8:11:14 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:11:8:11:14 | ... + ... | expression |
2- | test.cpp:11:8:11:14 | ... + ... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:11:8:11:14 | ... + ... | expression |
3- | test.cpp:13:8:13:13 | ... + ... | Implicit conversion converts cvalue $@ from signed short to signed int. | test.cpp:13:8:13:13 | ... + ... | expression |
1+ | test.cpp:12:8:12:14 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:12:8:12:14 | ... + ... | expression |
2+ | test.cpp:12:8:12:14 | ... + ... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:12:8:12:14 | ... + ... | expression |
3+ | test.cpp:14:8:14:13 | ... + ... | Implicit conversion converts cvalue $@ from signed short to signed int. | test.cpp:14:8:14:13 | ... + ... | expression |
4+ | test.cpp:23:13:23:19 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:23:13:23:19 | ... + ... | expression |
5+ | test.cpp:25:13:25:45 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:25:13:25:45 | static_cast<int8_t>... | expression |
6+ | test.cpp:31:12:31:18 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:31:12:31:18 | ... + ... | expression |
7+ | test.cpp:33:12:33:44 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:33:12:33:44 | static_cast<int8_t>... | expression |
Original file line number Diff line number Diff line change 11#include < cstdint>
2+
23void f1 () {
34 using std::int16_t ;
45 using std::int32_t ;
@@ -13,4 +14,24 @@ void f1() {
1314 l3 = l2 + 1 ; // NON_COMPLIANT
1415 l3 = static_cast <int32_t >(l2) + 1 ; // COMPLIANT
1516 l3 = l2 + 0x01ffff ; // COMPLIANT
17+ }
18+
19+ void int16_arg (std::int16_t t);
20+
21+ void test_func_call () {
22+ std::int8_t l1;
23+ int16_arg (l1 + l1); // NON_COMPLIANT
24+ int16_arg (static_cast <std::int16_t >(l1 + l1)); // COMPLIANT
25+ int16_arg (static_cast <std::int8_t >(l1 + l1)); // NON_COMPLIANT
26+ }
27+
28+ std::int16_t test_return (int test) {
29+ std::int8_t l1;
30+ if (test > 0 ) {
31+ return l1 + l1; // NON_COMPLIANT
32+ } else if (test < 0 ) {
33+ return static_cast <std::int8_t >(l1 + l1); // NON_COMPLIANT
34+ } else {
35+ return static_cast <std::int16_t >(l1 + l1); // COMPLIANT
36+ }
1637}
Original file line number Diff line number Diff line change @@ -18,4 +18,13 @@ void f1() {
1818 s16a = static_cast <int16_t >(f32a / f32b); // NON_COMPLIANT
1919 s16a = static_cast <int16_t >(f32a); // COMPLIANT
2020 s16a = static_cast <int16_t >(f32a) / f32b; // COMPLIANT
21+ }
22+
23+ void int_arg (std::int32_t i);
24+
25+ std::int16_t test_args () {
26+ float f32a;
27+ float f32b;
28+ int_arg (static_cast <std::int16_t >(f32a)); // COMPLIANT - f32a is not a cvalue
29+ return static_cast <std::int16_t >(f32a); // COMPLIANT - f32a is not a cvalue
2130}
Original file line number Diff line number Diff line change @@ -22,4 +22,22 @@ void f() {
2222 f64 = static_cast <double >(1 .0f + 1 .0f ); // NON_COMPLIANT
2323 f32 = static_cast <float >(1 .0f + 1 ); // COMPLIANT
2424 f64 = static_cast <double >(1.0 + 1 ); // COMPLIANT; no suffix defines a double
25+ }
26+
27+ #include < vector>
28+
29+ void function_args () {
30+ std::vector<std::uint8_t > v{0 };
31+
32+ std::uint32_t u32 {0 };
33+ v.at (static_cast <std::size_t >(u32 )); // COMPLIANT - cast is not a cvalue
34+ std::size_t st =
35+ static_cast <std::size_t >(u32 ); // COMPLIANT - cast is not a cvalue
36+ v.at (st);
37+ }
38+
39+ std::size_t return_args () {
40+ std::uint32_t u32 {0 };
41+
42+ return static_cast <std::size_t >(u32 ); // COMPLIANT
2543}
Original file line number Diff line number Diff line change 1- | test.cpp:16 :8:16 :35 | static_cast<int8_t>... | Explicit integral conversion converts the signedness of the $@ from unsigned to signed. | test.cpp:16 :28:16 :34 | ... + ... | cvalue |
2- | test.cpp:18 :8:18 :40 | static_cast<int8_t>... | Explicit integral conversion converts the signedness of the $@ from unsigned to signed. | test.cpp:18 :28:18 :39 | ... + ... | cvalue |
3- | test.cpp:20 :8:20 :35 | static_cast<int8_t>... | Explicit integral conversion converts the signedness of the $@ from unsigned to signed. | test.cpp:20 :28:20 :34 | ... * ... | cvalue |
1+ | test.cpp:20 :8:20 :35 | static_cast<int8_t>... | Explicit integral conversion converts the signedness of the $@ from unsigned to signed. | test.cpp:20 :28:20 :34 | ... + ... | cvalue |
2+ | test.cpp:22 :8:22 :40 | static_cast<int8_t>... | Explicit integral conversion converts the signedness of the $@ from unsigned to signed. | test.cpp:22 :28:22 :39 | ... + ... | cvalue |
3+ | test.cpp:24 :8:24 :35 | static_cast<int8_t>... | Explicit integral conversion converts the signedness of the $@ from unsigned to signed. | test.cpp:24 :28:24 :34 | ... * ... | cvalue |
Original file line number Diff line number Diff line change 11#include < cstdint>
2+
3+ void signed_arg (std::uint32_t s);
4+ void unsigned_arg (std::uint32_t u);
5+
26void f () {
37 using std::int16_t ;
48 using std::int32_t ;
@@ -22,4 +26,7 @@ void f() {
2226 i16 = static_cast <int16_t >(i16 / i8 ); // NON_COMPLIANT
2327
2428 i8 = static_cast <int8_t >(u8 ) + static_cast <int8_t >(u8 ); // COMPLIANT
29+
30+ unsigned (static_cast <uint32_t >(i32 )); // COMPLIANT - i32 is not a cvalue
31+ signed (static_cast <int32_t >(u32 )); // COMPLIANT - u32 is not a cvalue
2532}
Original file line number Diff line number Diff line change @@ -148,9 +148,9 @@ module MisraExpr {
148148 private predicate isCValue ( Expr e ) {
149149 not e .isConstant ( ) and
150150 (
151- exists ( ReturnStmt return | e = return .getExpr ( ) )
151+ exists ( ReturnStmt return | e = return .getExpr ( ) . getExplicitlyConverted ( ) )
152152 or
153- exists ( Call call | e = call .getAnArgument ( ) )
153+ exists ( FunctionCall call | e = call .getAnArgument ( ) . getExplicitlyConverted ( ) )
154154 )
155155 or
156156 isCValue ( e .( ParenthesisExpr ) .getExpr ( ) )
You can’t perform that action at this time.
0 commit comments