From: Eric Gallager <egall@gwmail.gwu.edu>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [RFA] [PATCH] Add a warning for invalid function casts
Date: Thu, 05 Oct 2017 18:22:00 -0000 [thread overview]
Message-ID: <CAMfHzOvQTbr2PzbP=eyQJ5H6bA5EghZ+U95st_MtfbvmLdxrpA@mail.gmail.com> (raw)
In-Reply-To: <AM5PR0701MB265755C5239565AE0AFB47B9E4700@AM5PR0701MB2657.eurprd07.prod.outlook.com>
On 10/5/17, Bernd Edlinger <bernd.edlinger@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
next prev parent reply other threads:[~2017-10-05 18:22 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-03 19:33 Bernd Edlinger
2017-10-03 21:34 ` Joseph Myers
2017-10-05 14:03 ` Bernd Edlinger
2017-10-05 14:10 ` Joseph Myers
2017-10-05 0:25 ` Eric Gallager
2017-10-05 13:39 ` Bernd Edlinger
2017-10-05 14:06 ` Andreas Schwab
2017-10-05 18:22 ` Eric Gallager [this message]
2017-10-05 16:16 ` Martin Sebor
2017-10-05 21:04 ` Bernd Edlinger
2017-10-05 21:47 ` Joseph Myers
2017-10-06 20:50 ` Jeff Law
2017-10-05 22:17 ` Martin Sebor
2017-10-06 13:26 ` Bernd Edlinger
2017-10-06 15:43 ` Martin Sebor
2017-10-06 18:25 ` Bernd Edlinger
2017-10-06 20:43 ` Martin Sebor
2017-10-06 21:01 ` Jeff Law
2017-10-06 22:23 ` Bernd Edlinger
2017-10-07 18:23 ` Bernd Edlinger
2017-10-09 16:48 ` Martin Sebor
2017-10-09 18:19 ` Bernd Edlinger
2017-10-09 18:46 ` Martin Sebor
2017-10-09 22:33 ` Bernd Edlinger
2017-10-10 15:35 ` Martin Sebor
2017-10-10 16:55 ` Joseph Myers
2017-10-10 17:39 ` Martin Sebor
2017-10-10 23:57 ` Joseph Myers
2017-10-11 3:52 ` Martin Sebor
2017-10-11 17:28 ` Joseph Myers
2017-10-11 18:04 ` Martin Sebor
2017-10-12 11:45 ` Pedro Alves
2017-10-12 11:52 ` Pedro Alves
2017-10-12 11:59 ` Pedro Alves
2017-10-12 15:26 ` Martin Sebor
2017-10-12 15:37 ` Joseph Myers
2017-10-21 9:54 ` Bernd Edlinger
2017-11-03 21:47 ` Joseph Myers
[not found] ` <fa771535-8fcf-9b22-b5b9-eb928af5e817@hotmail.de>
2017-11-08 17:03 ` [PING] " Bernd Edlinger
[not found] ` <e64a07da-bada-893e-d1e4-bf4705cc1731@hotmail.de>
2017-11-15 20:52 ` [PING**2] " Bernd Edlinger
2017-11-29 22:17 ` Jason Merrill
2017-11-30 15:45 ` [PATCHv2] " Bernd Edlinger
2017-11-30 15:56 ` Jason Merrill
2017-11-30 16:22 ` Bernd Edlinger
2017-11-30 17:32 ` Jason Merrill
2017-11-30 18:06 ` Bernd Edlinger
2017-11-30 18:19 ` Jason Merrill
2017-11-30 18:39 ` Bernd Edlinger
2017-11-30 18:39 ` Jason Merrill
2017-12-01 12:42 ` [PATCHv3] " Bernd Edlinger
2017-12-06 22:36 ` Jason Merrill
2017-12-07 20:48 ` Bernd Edlinger
2017-12-14 18:50 ` Jason Merrill
[not found] ` <1c3d1b9b-7a25-fae3-5c44-1a0efae77cc8@hotmail.de>
2017-12-14 18:35 ` Bernd Edlinger
2017-10-08 16:47 [RFA] [PATCH] " Eric Gallager
2017-10-08 18:05 Eric Gallager
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMfHzOvQTbr2PzbP=eyQJ5H6bA5EghZ+U95st_MtfbvmLdxrpA@mail.gmail.com' \
--to=egall@gwmail.gwu.edu \
--cc=bernd.edlinger@hotmail.de \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).