From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36666 invoked by alias); 23 Feb 2018 20:32:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 36657 invoked by uid 89); 23 Feb 2018 20:32:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL autolearn=no version=3.3.2 spammy=Casting, consciously X-HELO: homiemail-a82.g.dreamhost.com Received: from sub5.mail.dreamhost.com (HELO homiemail-a82.g.dreamhost.com) (208.113.200.129) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 23 Feb 2018 20:32:23 +0000 Received: from homiemail-a82.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a82.g.dreamhost.com (Postfix) with ESMTP id 86270600732B; Fri, 23 Feb 2018 12:32:21 -0800 (PST) Received: from linaro-laptop.intra.reserved-bit.com (unknown [123.252.202.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by homiemail-a82.g.dreamhost.com (Postfix) with ESMTPSA id D479F600731B; Fri, 23 Feb 2018 12:32:19 -0800 (PST) Subject: Re: [PATCH] Fix bogus function cast warning for functions with common arg subset To: Martin Sebor , Richard Biener , gcc-patches@gcc.gnu.org, David Malcolm References: <20180223034045.26231-1-siddhesh@sourceware.org> <1519401043.2913.34.camel@redhat.com> <6b766ed9-1da3-7712-1d0c-1a50f2c44d38@sourceware.org> From: Siddhesh Poyarekar Message-ID: <4dfc6ad1-f3a8-e4d5-0629-65d8becfd50c@sourceware.org> Date: Fri, 23 Feb 2018 20:32:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-02/txt/msg01352.txt.bz2 On Saturday 24 February 2018 01:32 AM, Martin Sebor wrote: > Casting the address of a function that takes one or more arguments > to one that takes fewer is unsafe because when the pointer is used > to call the function the extra arguments have indeterminate values. > (This is also why void(*)(void) as a wildcard was a poor choice: > because it's only safe when it's an exact match.) > > Casting in the opposite direction (fewer arguments to more) can > also lead to bugs under ABIs where the callee is responsible for > restoring the frame pointer. I completely agree about the safety aspect of it, but my argument is about user experience, not safety. We are after all talking about explicit casts, i.e. cast decisions that users have consciously made. > The intent behind the warning is to help find instances of these > conversions that are unsafe and to drive improvements to code and > get it to adopt a single common wildcard.=C2=A0 The current choice > isn't ideal but expanding it even further would compromise > the goal of the warning even more. While varargs may solve a lot of these problems, the best viable solution or cases where such casts are necessary seems to be to switch off the warning, which kinda defeats the goal anyway. IMO we're better off making the warnings as less intrusive as possible to begin with and then gradually make them more aggressive. Siddhesh