]> git.ozlabs.org Git - ccan/blobdiff - ccan/tlist2/test/compile_fail-tlist_for_each_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_2.c
diff --git a/ccan/tlist2/test/compile_fail-tlist_for_each_2.c b/ccan/tlist2/test/compile_fail-tlist_for_each_2.c
new file mode 100644 (file)
index 0000000..776d141
--- /dev/null
@@ -0,0 +1,32 @@
+#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;
+#else
+       struct child *c;
+#endif
+
+       tlist2_init(&children);
+       tlist2_add(&children, &child);
+
+       tlist2_for_each(&children, c)
+               (void) c; /* Suppress unused-but-set-variable warning. */
+       return 0;
+}