This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFA] [PATCH] Add a warning for invalid function casts
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: Martin Sebor <msebor at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 6 Oct 2017 13:25:55 +0000
- Subject: Re: [RFA] [PATCH] Add a warning for invalid function casts
- Authentication-results: sourceware.org; auth=none
- Authentication-results: outbound.protection.outlook.com; spf=skipped (originating message); dkim=none (message not signed) header.d=none; dmarc=none action=none header.from=hotmail.de;
- References: <AM5PR0701MB265700BCFDF7620223717DCCE4720@AM5PR0701MB2657.eurprd07.prod.outlook.com> <1644e85e-6d3a-a114-32b5-a9b49de24407@gmail.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On 10/05/17 18:16, Martin Sebor wrote:
> In my (very quick) tests the warning appears to trigger on all
> strictly incompatible conversions, even if they are otherwise
> benign, such as:
>
> int f (const int*);
> typedef int F (int*);
>
> F* pf1 = f; // -Wincompatible-pointer-types
> F* pf2 = (F*)f; // -Wcast-function-type
>
> Likewise by:
>
> int f (signed char);
> typedef int F (unsigned char);
>
> F* pf = (F*)f; // -Wcast-function-type
>
> I'd expect these conversions to be useful and would view warning
> for them with -Wextra as excessive. In fact, I'm not sure I see
> the benefit of warning on these casts under any circumstances.
>
Well, while the first example should be safe,
the second one is probably not safe:
Because the signed and unsigned char are promoted to int,
by the ABI but one is in the range -128..127 while the
other is in the range 0..255, right?
Bernd.