X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcontainer_of%2Ftest%2Fcompile_fail-bad-type.c;fp=ccan%2Fcontainer_of%2Ftest%2Fcompile_fail-bad-type.c;h=01dfd454597d0eb7d43244a3af81396e1648fc70;hp=0000000000000000000000000000000000000000;hb=650c775ff00cccd03fc84e7789a03c51d9839004;hpb=c8acddea39d222312102952e91c32cfe4dd2cea0 diff --git a/ccan/container_of/test/compile_fail-bad-type.c b/ccan/container_of/test/compile_fail-bad-type.c new file mode 100644 index 00000000..01dfd454 --- /dev/null +++ b/ccan/container_of/test/compile_fail-bad-type.c @@ -0,0 +1,22 @@ +#include "container_of/container_of.h" +#include + +struct foo { + int a; + char b; +}; + +int main(int argc, char *argv[]) +{ + struct foo foo = { .a = 1, .b = 2 }; + int *intp = &foo.a; + char *p; + +#ifdef FAIL + /* p is a char *, but this gives a struct foo * */ + p = container_of(intp, struct foo, a); +#else + p = (char *)intp; +#endif + return p == NULL; +}