diff --git a/ccan/check_type/check_type.h b/ccan/check_type/check_type.h index 837aef7b1..9df25a970 100644 --- a/ccan/check_type/check_type.h +++ b/ccan/check_type/check_type.h @@ -49,8 +49,12 @@ #define check_type(expr, type) \ ((typeof(expr) *)0 != (type *)0) -#define check_types_match(expr1, expr2) \ +#define _check_types_match(expr1, expr2) \ ((typeof(expr1) *)0 != (typeof(expr2) *)0) + +#define check_types_match(expr1, expr2) \ + _check_types_match((const typeof(expr1) *)0, \ + (const typeof(expr2) *)0) #else #include /* Without typeof, we can only test the sizes. */ diff --git a/ccan/container_of/test/compile_fail-bad-void-type.c b/ccan/container_of/test/compile_fail-bad-void-type.c new file mode 100644 index 000000000..1faa8955d --- /dev/null +++ b/ccan/container_of/test/compile_fail-bad-void-type.c @@ -0,0 +1,26 @@ +#include +#include + +struct foo { + int *a; + char b; +}; + +int main(void) +{ + struct foo foo = { .a = NULL, .b = 2 }; + void *voidp = &foo.a; + const char *ccharp = &foo.b; + char *charp = &foo.b; + struct foo *p; + +#ifdef FAIL + /* voidp is a void * but b is an int */ + p = container_of(voidp, struct foo, a); +#else + p = voidp; + p = container_of(ccharp, struct foo, b); + p = container_of(charp, struct foo, b); +#endif + return p == NULL; +}