]> git.ozlabs.org Git - ccan/blob - ccan/typesafe_cb/test/compile_fail-typesafe_cb.c
bd20131368cf35dd2bc636d9f0d2bf44f3bd0557
[ccan] / ccan / typesafe_cb / test / compile_fail-typesafe_cb.c
1 #include <ccan/typesafe_cb/typesafe_cb.h>
2 #include <stdlib.h>
3
4 static void _register_callback(void (*cb)(void *arg), void *arg)
5 {
6 }
7
8 #define register_callback(cb, arg)                              \
9         _register_callback(typesafe_cb(void, (cb), (arg)), (arg))
10
11 static void my_callback(char *p)
12 {
13 }
14
15 int main(int argc, char *argv[])
16 {
17 #ifdef FAIL
18         int *p;
19 #if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P
20 #error "Unfortunately we don't fail if cast_if_type is a noop."
21 #endif
22 #else
23         char *p;
24 #endif
25         p = NULL;
26
27         /* This should work always. */
28         register_callback(my_callback, "hello world");
29
30         /* This will fail with FAIL defined */
31         register_callback(my_callback, p);
32         return 0;
33 }