c/5459: gcc 3.0.x sometimes prints incorrect warning for function pointer casts
espenlaub@informatik.uni-ulm.de
espenlaub@informatik.uni-ulm.de
Wed Jan 23 02:36:00 GMT 2002
>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;
}
More information about the Gcc-prs
mailing list