Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqM5P-000115-Gk for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jun 2020 19:38:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jqM5N-0003eR-F7 for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jun 2020 19:38:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqM5N-0003eI-8E for pgsql-hackers@lists.postgresql.org; Tue, 30 Jun 2020 19:38:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqM5K-00047T-7Y for pgsql-hackers@postgresql.org; Tue, 30 Jun 2020 19:38:28 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 05UJcKO9496553; Tue, 30 Jun 2020 15:38:20 -0400 From: Tom Lane To: Andres Freund cc: Peter Eisentraut , pgsql-hackers Subject: Re: warnings for invalid function casts 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> Comments: In-reply-to Andres Freund message dated "Tue, 30 Jun 2020 12:21:35 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <496551.1593545900.1@sss.pgh.pa.us> Date: Tue, 30 Jun 2020 15:38:20 -0400 Message-ID: <496552.1593545900@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund 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