From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4393 invoked by alias); 23 Jan 2002 10:36:04 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 4360 invoked by uid 71); 23 Jan 2002 10:36:02 -0000 Resent-Date: 23 Jan 2002 10:36:02 -0000 Resent-Message-ID: <20020123103602.4357.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, espenlaub@informatik.uni-ulm.de Received:(qmail 3191 invoked by uid 61); 23 Jan 2002 10:29:17 -0000 Message-Id:<20020123102917.3190.qmail@sources.redhat.com> Date: Wed, 23 Jan 2002 02:36:00 -0000 From: espenlaub@informatik.uni-ulm.de Reply-To: espenlaub@informatik.uni-ulm.de To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/5459: gcc 3.0.x sometimes prints incorrect warning for function pointer casts X-SW-Source: 2002-01/txt/msg00822.txt.bz2 List-Id: >Number: 5459 >Category: c >Synopsis: gcc 3.0.x sometimes prints incorrect warning for function pointer casts >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Wed Jan 23 02:36:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: Klaus Espenlaub >Release: gcc-3.0.3 >Organization: >Environment: System: Linux croc 2.4.7-4GB #1 Thu Oct 25 17:53:12 GMT 2001 i686 unknown Architecture: i686 >Description: If -Wcast-qual warnings are enabled, then gcc prints a warning message for the attached code: gcc3-wbug.c:9: warning: cast discards qualifiers from pointer target type I looked at the code which prints that, and my guess is that it doesn't handle the type qualifiers for function types correctly: const means that a function has no side effects, and that is always compatible with non-const function types. Essentially the rule for function type compatibility is exactly the opposite as for normal pointers. I came across this issue because gcc-3 seems to be able to automatically infer the "const" qualifier for functions that are simple enough. The bug itself may be old, but surfaced because of the new feature. >How-To-Repeat: gcc -Wcast-qual -c gcc3-wbug.c to compile the attached file (gcc3-wbug.c) >Fix: Sorry, no patch. I don't know enough about that part of the compiler to fix it without breaking other things. >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="gcc3-wbug.c" Content-Disposition: inline; filename="gcc3-wbug.c" typedef void (*fp)(int); static void func(void) { } static fp tab[] = { (fp)func }; int main(void) { (void)tab; return 0; }