X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fcontainer_of%2Ftest%2Fcompile_fail-var-types.c;fp=ccan%2Fcontainer_of%2Ftest%2Fcompile_fail-var-types.c;h=5c7767985223b62259a7cea1c08c0dd8e60fc630;hb=650c775ff00cccd03fc84e7789a03c51d9839004;hp=0000000000000000000000000000000000000000;hpb=c8acddea39d222312102952e91c32cfe4dd2cea0;p=ccan diff --git a/ccan/container_of/test/compile_fail-var-types.c b/ccan/container_of/test/compile_fail-var-types.c new file mode 100644 index 00000000..5c776798 --- /dev/null +++ b/ccan/container_of/test/compile_fail-var-types.c @@ -0,0 +1,21 @@ +#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 }, *foop; + int *intp = &foo.a; + +#ifdef FAIL + /* b is a char, but intp is an int * */ + foop = container_of_var(intp, foop, b); +#else + foop = NULL; +#endif + return intp == NULL; +}