On 10/5/17, Bernd Edlinger <bernd.edlin...@hotmail.de> wrote: > On 10/05/17 02:24, Eric Gallager wrote: >> Sorry if this is a stupid question, but could you explain how this >> warning is different from -Wbad-function-cast? Something about direct >> calls to functions vs. passing them as function pointers? > > No, it is not :) > > -Wbad-function-cast is IMHO a strange legacy warning. > > It is C-only, and it triggers only if the result of a function call > is cast to a type with a different TREE_CODE, so for instance > int <-> float <-> pointer. > > It would trigger for perfectly valid code like this: > > i = (int) floor (f); > > while we have no warning for > > i = floor (f); > > What I want to diagnose is assigning a function pointer via an explicit > type cast to another function pointer, when there is no possible > implicit conversion between the two function pointer types. > Thus the cast was used to silence a warning/error in the first place.
OK, thanks for explaining! I kinda worry about warning on code that was added to silence other warnings in the first place, as it can lead to frustration when making a fix expecting the number of warnings when compiling to decrease, but then they don't actually decrease. But as long as there's a simple way to fix the warned-on code that silences both the original warning being avoided, and this new one, I see how it'll be useful. > > The idea for this warning came up when someone spotted a place in > openssl, where a type cast was used to change the return value of a > callback function from long to int: > > https://github.com/openssl/openssl/issues/4413 > > But due to the type cast there was never ever any warning from this > invalid type cast. > > > Bernd. > Thanks for working on this! Eric