X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftypesafe_cb%2Ftest%2Fcompile_fail-typesafe_cb.c;fp=ccan%2Ftypesafe_cb%2Ftest%2Fcompile_fail-typesafe_cb.c;h=d305d5fb1101fc1c3a242346f97a5218fd166744;hp=0000000000000000000000000000000000000000;hb=650c775ff00cccd03fc84e7789a03c51d9839004;hpb=c8acddea39d222312102952e91c32cfe4dd2cea0 diff --git a/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c b/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c new file mode 100644 index 00000000..d305d5fb --- /dev/null +++ b/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c @@ -0,0 +1,33 @@ +#include "typesafe_cb/typesafe_cb.h" +#include + +static void _register_callback(void (*cb)(void *arg), void *arg) +{ +} + +#define register_callback(cb, arg) \ + _register_callback(typesafe_cb(void, (cb), (arg)), (arg)) + +static void my_callback(char *p) +{ +} + +int main(int argc, char *argv[]) +{ +#ifdef FAIL + int *p; +#if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P +#error "Unfortunately we don't fail if cast_if_type is a noop." +#endif +#else + char *p; +#endif + p = NULL; + + /* This should work always. */ + register_callback(my_callback, "hello world"); + + /* This will fail with FAIL defined */ + register_callback(my_callback, p); + return 0; +}