extra: tweak hard max in conditions and macros
[smatch.git] / validation / sizeof-void.c
blob0fd917a21fb296a95da0fcd6119618e8e3111417
1 #define is_constexpr(x) \
2 (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
4 static int test(void)
6 unsigned int s = 0, i = 0;
7 void *ptr = &i;
9 // OK
10 s += sizeof i;
11 s += sizeof &i;
12 s += sizeof ptr;
13 s += sizeof &ptr;
15 // KO
16 s += sizeof(void);
17 s += sizeof *ptr;
18 s += is_constexpr(ptr++);
19 s += is_constexpr((i++, 1));
20 s += is_constexpr(sizeof *ptr);
21 s += is_constexpr(ptr + 1);
22 s += is_constexpr(&ptr + 1);
23 s += is_constexpr(*(((char *)&ptr) + 1));
25 return s;
29 * check-name: sizeof(void) is valid
30 * check-description: sizeof(void) was rejected because void is an incomplete
31 * type
32 * check-command: sparse -Wpointer-arith $file
34 * check-error-start
35 sizeof-void.c:16:14: warning: expression using sizeof(void)
36 sizeof-void.c:17:14: warning: expression using sizeof(void)
37 sizeof-void.c:18:14: warning: expression using sizeof(void)
38 sizeof-void.c:19:14: warning: expression using sizeof(void)
39 sizeof-void.c:20:14: warning: expression using sizeof(void)
40 sizeof-void.c:21:14: warning: expression using sizeof(void)
41 sizeof-void.c:22:14: warning: expression using sizeof(void)
42 sizeof-void.c:23:14: warning: expression using sizeof(void)
43 * check-error-end