From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: warnings for invalid function casts
Date: Tue, 30 Jun 2020 15:38:20 -0400
Message-ID: <496552.1593545900@sss.pgh.pa.us> (raw)
In-Reply-To: <20200630192135.nwlza2u57dy3qej4@alap3.anarazel.de>
References: <1e97628e-6447-b4fd-e230-d109cec2d584@2ndquadrant.com>
<474790.1593526505@sss.pgh.pa.us>
<20200630192135.nwlza2u57dy3qej4@alap3.anarazel.de>
Andres Freund <andres@anarazel.de> writes:
> On 2020-06-30 10:15:05 -0400, Tom Lane wrote:
>> I feel like what you propose to do here is just shifting the problem
>> around: we're still casting from a function pointer that describes one
>> concrete call ABI to a function pointer that describes some other concrete
>> call ABI. That is, "void (*ptr) (void)" is *not* disclaiming knowledge
>> of the function's signature, in the way that "void *ptr" disclaims
>> knowledge of what a data pointer points to. So if current gcc fails to
>> warn about that, that's just a random and indeed obviously wrong decision
>> that they might change someday.
> ISTM that it's unlikely that they'd warn about casting from one
> signature to another?
Uh, what? Isn't that *exactly* what this warning class does?
If it doesn't do that, what good is it? I mean, I can definitely
see the point of warning when you cast a function pointer to some
other not-ABI-compatible function pointer type, because that might
be a mistake, just like assigning "int *" to "double *" might be.
gcc 8's manual says
'-Wcast-function-type'
Warn when a function pointer is cast to an incompatible function
pointer. In a cast involving function types with a variable
argument list only the types of initial arguments that are provided
are considered. Any parameter of pointer-type matches any other
pointer-type. Any benign differences in integral types are
ignored, like 'int' vs. 'long' on ILP32 targets. Likewise type
qualifiers are ignored. The function type 'void (*) (void)' is
special and matches everything, which can be used to suppress this
warning. In a cast involving pointer to member types this warning
warns whenever the type cast is changing the pointer to member
type. This warning is enabled by '-Wextra'.
so it seems like they've already mostly crippled the type-safety of the
warning with the provision about "all pointer types are interchangeable"
:-(. But they certainly are warning about *some* cases of casting one
signature to another.
In any case, I think the issue here is what is the escape hatch for saying
that "I know this cast is okay, don't warn about it, thanks". Treating
"void (*) (void)" as special for that purpose is nothing more nor less
than a kluge, so another compiler might do it differently. Given the
POSIX restriction, I think we could reasonably use "void *" instead.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, peter.eisentraut@2ndquadrant.com
Subject: Re: warnings for invalid function casts
In-Reply-To: <496552.1593545900@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox