forked from cppcheck-opensource/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisra-test-c11.c
More file actions
38 lines (34 loc) · 1.16 KB
/
misra-test-c11.c
File metadata and controls
38 lines (34 loc) · 1.16 KB
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
38
// To test:
// ~/cppcheck/cppcheck --dump misra/misra-test-c11.c --std=c11
// ~/cppcheck/cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test-c11.c --std=c11 --platform=unix64 && python3 ../misra.py -verify misra/misra-test-c11.c.dump
#include <stdbool.h>
#include <stdint.h>
typedef unsigned int UINT_TYPEDEF;
struct struct_with_bitfields
{
unsigned int a:2; // Compliant
signed int b:2; // Compliant
UINT_TYPEDEF c:2; // Compliant
int d:2; // 6.1 - plain int not compliant
signed long f:2; // Compliant in c99 or later - explicitly signed integer type
unsigned int g:1; // Compliant
signed int h:1; // 6.2 - signed int with size 1 is not compliant
uint16_t i:1; // Compliant
bool j:1; // Compliant in C99 or later
};
static void misra6_1_fn(void) {
// "Use" occurrence should not generate warnings
struct_with_bitfields s;
s.h = 61;
}
static void misra_10_3_c11(void) {
bool b = false;
bool b0 = 0; // 10.3
bool b1 = 1; // 10.3
bool bf = false; // no-warning
bool bt = true; // no-warning
b = 0; // 10.3
b = 1; // 10.3
b = false; // no-warning
b = true; // no-warning
}