tcon: Encode information on container members in "type" canaries
[ccan] / ccan / tcon / test / compile_fail-container1w.c
1 #include <stdlib.h>
2
3 #include <ccan/tcon/tcon.h>
4 #include <ccan/build_assert/build_assert.h>
5 #include <ccan/tap/tap.h>
6
7 struct inner {
8         int inner_val;
9 };
10
11 struct outer {
12         int outer_val;
13         struct inner inner;
14 };
15
16 struct info_base {
17         char *infop;
18 };
19
20 int main(int argc, char *argv[])
21 {
22         TCON_WRAP(struct info_base,
23                   TCON_CONTAINER(concan, struct outer, inner)) info;
24         struct outer ovar;
25 #ifdef FAIL
26 #if !HAVE_TYPEOF
27 #error We cannot detect type problems without HAVE_TYPEOF
28 #endif
29         int *innerp = &ovar.outer_val;
30 #else
31         struct inner *innerp = &ovar.inner;
32 #endif
33
34         return tcon_container_of(&info, concan, innerp) == &ovar;
35 }