]> git.ozlabs.org Git - ccan/blobdiff - ccan/hashtable/test/compile_ok-traverse.c
hashtable: fix traverse typesafety.
[ccan] / ccan / hashtable / test / compile_ok-traverse.c
diff --git a/ccan/hashtable/test/compile_ok-traverse.c b/ccan/hashtable/test/compile_ok-traverse.c
new file mode 100644 (file)
index 0000000..365180d
--- /dev/null
@@ -0,0 +1,49 @@
+#include <ccan/hashtable/hashtable.h>
+#include <ccan/hashtable/hashtable.c>
+
+struct foo {
+       int i;
+};
+
+struct bar {
+       int i;
+};
+
+static bool fn_foo_bar(struct foo *foo, struct bar *bar)
+{
+       return true;
+}
+
+static bool fn_const_foo_bar(const struct foo *foo, struct bar *bar)
+{
+       return true;
+}
+
+static bool fn_foo_const_bar(struct foo *foo, const struct bar *bar)
+{
+       return true;
+}
+
+static bool fn_const_foo_const_bar(const struct foo *foo,
+                                  const struct bar *bar)
+{
+       return true;
+}
+
+static bool fn_void_void(void *foo, void *bar)
+{
+       return true;
+}
+
+int main(void)
+{
+       struct hashtable *ht = NULL;
+       struct bar *bar = NULL;
+
+       hashtable_traverse(ht, struct foo, fn_foo_bar, bar);
+       hashtable_traverse(ht, struct foo, fn_const_foo_bar, bar);
+       hashtable_traverse(ht, struct foo, fn_foo_const_bar, bar);
+       hashtable_traverse(ht, struct foo, fn_const_foo_const_bar, bar);
+       hashtable_traverse(ht, struct foo, fn_void_void, bar);
+       return 0;
+}