]> git.ozlabs.org Git - ccan/commitdiff
Compile even with !HAVE_TYPEOF etc, and remove redundant test case.
authorRusty Russell <rusty@vivaldi>
Thu, 28 Feb 2008 04:20:36 +0000 (15:20 +1100)
committerRusty Russell <rusty@vivaldi>
Thu, 28 Feb 2008 04:20:36 +0000 (15:20 +1100)
typesafe_cb/test/compile_fail-cast_if_type-callback-int.c [deleted file]
typesafe_cb/test/compile_fail-cast_if_type-callback.c [deleted file]
typesafe_cb/test/compile_fail-cast_if_type.c
typesafe_cb/test/compile_fail-typesafe_cb-int.c [new file with mode: 0644]
typesafe_cb/test/compile_fail-typesafe_cb.c
typesafe_cb/test/compile_fail-typesafe_cb_postargs.c
typesafe_cb/test/compile_fail-typesafe_cb_preargs.c

diff --git a/typesafe_cb/test/compile_fail-cast_if_type-callback-int.c b/typesafe_cb/test/compile_fail-cast_if_type-callback-int.c
deleted file mode 100644 (file)
index 85006c9..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "typesafe_cb/typesafe_cb.h"
-#include <stdlib.h>
-
-void _callback(void (*fn)(void *arg), void *arg);
-void _callback(void (*fn)(void *arg), void *arg)
-{
-       fn(arg);
-}
-
-/* Callback is set up to warn if arg isn't a pointer (since it won't
- * pass cleanly to _callback's second arg. */
-#define callback(fn, arg)                                              \
-       _callback(cast_if_type((fn), void (*)(typeof(arg)), void (*)(void *)), \
-                 arg)
-
-void my_callback(int something);
-void my_callback(int something)
-{
-}
-
-int main(int argc, char *argv[])
-{
-#ifdef FAIL
-       callback(my_callback, 100);
-#endif
-       return 0;
-}
diff --git a/typesafe_cb/test/compile_fail-cast_if_type-callback.c b/typesafe_cb/test/compile_fail-cast_if_type-callback.c
deleted file mode 100644 (file)
index 313a53e..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "typesafe_cb/typesafe_cb.h"
-#include <stdlib.h>
-
-static void _callback(void (*fn)(void *arg), void *arg)
-{
-       fn(arg);
-}
-
-#define callback(fn, arg)                                              \
-       _callback(cast_if_type((fn), void (*)(typeof(arg)), void (*)(void *)), \
-                 arg)
-
-static void my_callback(char *p)
-{
-}
-
-int main(int argc, char *argv[])
-{
-       callback(my_callback, "hello world");
-
-#ifdef FAIL
-       /* Must be a char * */
-       callback(my_callback, my_callback);
-#endif
-       return 0;
-}
index 2ab3fa2398f29fa6940f4952471467195202e08b..1e417cbac6bb869b43693087fe827380389d1cf8 100644 (file)
@@ -14,6 +14,9 @@ int main(int argc, char *argv[])
 #ifdef FAIL
        int x = 0;
        set_some_value(x);
+#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
        void *p = 0;
        set_some_value(p);
diff --git a/typesafe_cb/test/compile_fail-typesafe_cb-int.c b/typesafe_cb/test/compile_fail-typesafe_cb-int.c
new file mode 100644 (file)
index 0000000..54d0e7b
--- /dev/null
@@ -0,0 +1,27 @@
+#include "typesafe_cb/typesafe_cb.h"
+#include <stdlib.h>
+
+void _callback(void (*fn)(void *arg), void *arg);
+void _callback(void (*fn)(void *arg), void *arg)
+{
+       fn(arg);
+}
+
+/* Callback is set up to warn if arg isn't a pointer (since it won't
+ * pass cleanly to _callback's second arg. */
+#define callback(fn, arg)                                              \
+       _callback(typesafe_cb(void, (fn), (arg)), (arg))
+
+void my_callback(int something);
+void my_callback(int something)
+{
+}
+
+int main(int argc, char *argv[])
+{
+#ifdef FAIL
+       /* This fails due to arg, not due to cast. */
+       callback(my_callback, 100);
+#endif
+       return 0;
+}
index 340500891fc8c62de1dac3a0928ee8d6e52c1282..d305d5fb1101fc1c3a242346f97a5218fd166744 100644 (file)
@@ -16,10 +16,18 @@ 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;
 }
index e6ec82606cef107bcb79b62cfa464257c7cfd811..099eb25755559e1c26fd3d807c265d7bf7f55071 100644 (file)
@@ -15,6 +15,9 @@ 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
index ce1ada2f496e1a10903ca9f96d6fb1532fe6e242..38daec51063fb718964d59abb08dd658c76b1139 100644 (file)
@@ -16,6 +16,9 @@ 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