]> git.ozlabs.org Git - ccan/blobdiff - ccan/tlist2/test/compile_fail-tlist_for_each_safe_2.c
tlist2: a alternate to tlist that encodes the member offset into the container type
[ccan] / ccan / tlist2 / test / compile_fail-tlist_for_each_safe_2.c
diff --git a/ccan/tlist2/test/compile_fail-tlist_for_each_safe_2.c b/ccan/tlist2/test/compile_fail-tlist_for_each_safe_2.c
new file mode 100644 (file)
index 0000000..d06f64a
--- /dev/null
@@ -0,0 +1,31 @@
+#include <ccan/tlist2/tlist2.h>
+
+struct child {
+       const char *name;
+       struct list_node list;
+};
+
+struct cousin {
+       const char *name;
+       struct list_node list;
+};
+
+int main(int argc, char *argv[])
+{
+       TLIST2(struct child, list) children;
+       struct child child = { "child" };
+#ifdef FAIL
+#if !HAVE_FLEXIBLE_ARRAY_MEMBER
+#error Need flexible array members to check type
+#endif
+       struct cousin *c, *n;
+#else
+       struct child *c, *n;
+#endif
+
+       tlist2_init(&children);
+       tlist2_add(&children, &child);
+
+       tlist2_for_each_safe(&children, c, n);
+       return 0;
+}