summaryrefslogtreecommitdiffstats
path: root/lib/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c')
-rw-r--r--lib/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c b/lib/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c
new file mode 100644
index 00000000000..81e36d7b87b
--- /dev/null
+++ b/lib/ccan/typesafe_cb/test/compile_fail-typesafe_cb.c
@@ -0,0 +1,34 @@
+#include <ccan/typesafe_cb/typesafe_cb.h>
+#include <stdlib.h>
+
+static void _register_callback(void (*cb)(void *arg), void *arg)
+{
+}
+
+#define register_callback(cb, arg) \
+ _register_callback(typesafe_cb(void, void *, (cb), (arg)), (arg))
+
+static void my_callback(char *p)
+{
+}
+
+int main(int argc, char *argv[])
+{
+ char str[] = "hello world";
+#ifdef FAIL
+ int *p;
+#if !HAVE_TYPEOF||!HAVE_BUILTIN_CHOOSE_EXPR||!HAVE_BUILTIN_TYPES_COMPATIBLE_P
+#error "Unfortunately we don't fail if typesafe_cb_cast is a noop."
+#endif
+#else
+ char *p;
+#endif
+ p = NULL;
+
+ /* This should work always. */
+ register_callback(my_callback, str);
+
+ /* This will fail with FAIL defined */
+ register_callback(my_callback, p);
+ return 0;
+}