the folowing testcase does a casting which results in undefined behaviour but gcc does not warn about it. ypedef int (*bar_t)(int x, int y, ...); int foo(int x, int y) { return x+y; } void f(int x, int y) { bar_t bar; /* Cast foo to variadic type... undefined behaviour */ bar = (bar_t) foo; (*bar)(x,y); }
Joseph, what do you think? Any suggestions where this may be catched? wording? option? I have wished for some time to create a -Wundefined option anyway.
Subject: Re: gcc does not warn about casting non-variadic types to variadic types It's not the conversion that's undefined, but the call. You could have an option to warn for all function pointer conversions to incompatible function pointer types (but they have reasonable uses as there isn't a generic function pointer type like void *) - or you could have the optimizers detect calls to incompatibly cast types and warn then like the front ends does when the cast appears directly in the call.
OK. So I would say confirmed, but still I am not sure how I would implement this. So patches welcome.