]> git.ozlabs.org Git - ccan/blobdiff - ccan/tcon/test/compile_fail-container3w.c
tcon: Encode information on container members in "type" canaries
[ccan] / ccan / tcon / test / compile_fail-container3w.c
diff --git a/ccan/tcon/test/compile_fail-container3w.c b/ccan/tcon/test/compile_fail-container3w.c
new file mode 100644 (file)
index 0000000..6930b43
--- /dev/null
@@ -0,0 +1,36 @@
+#include <stdlib.h>
+
+#include <ccan/tcon/tcon.h>
+#include <ccan/build_assert/build_assert.h>
+#include <ccan/tap/tap.h>
+
+struct inner {
+       int inner_val;
+};
+
+struct outer {
+       int outer_val;
+       struct inner inner;
+};
+
+struct info_base {
+       char *infop;
+};
+
+int main(int argc, char *argv[])
+{
+       TCON_WRAP(struct info_base,
+                 TCON_CONTAINER(concan, struct outer, inner)) info;
+       struct outer ovar;
+#ifdef FAIL
+#if !HAVE_TYPEOF
+#error We cannot detect type problems without HAVE_TYPEOF
+#endif
+       int *outerp;
+#else
+       struct outer *outerp;
+#endif
+
+       outerp = tcon_container_of(&info, concan, &ovar.inner);
+       return outerp != NULL;
+}