-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathtest.cpp
37 lines (31 loc) · 952 Bytes
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <cstdint>
void f1() {
using std::int16_t;
using std::int32_t;
using std::int8_t;
int8_t l1;
int16_t l2;
int32_t l3;
l2 = l1 + l1; // NON_COMPLIANT
l2 = static_cast<int16_t>(l1) + l1; // COMPLIANT
l3 = l2 + 1; // NON_COMPLIANT
l3 = static_cast<int32_t>(l2) + 1; // COMPLIANT
l3 = l2 + 0x01ffff; // COMPLIANT
}
void int16_arg(std::int16_t t);
void test_func_call() {
std::int8_t l1;
int16_arg(l1 + l1); // NON_COMPLIANT
int16_arg(static_cast<std::int16_t>(l1 + l1)); // COMPLIANT
int16_arg(static_cast<std::int8_t>(l1 + l1)); // NON_COMPLIANT
}
std::int16_t test_return(int test) {
std::int8_t l1;
if (test > 0) {
return l1 + l1; // NON_COMPLIANT
} else if (test < 0) {
return static_cast<std::int8_t>(l1 + l1); // NON_COMPLIANT
} else {
return static_cast<std::int16_t>(l1 + l1); // COMPLIANT
}
}