public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: espenlaub@informatik.uni-ulm.de
To: gcc-gnats@gcc.gnu.org
Subject: c/5459: gcc 3.0.x sometimes prints incorrect warning for function pointer casts
Date: Wed, 23 Jan 2002 02:36:00 -0000	[thread overview]
Message-ID: <20020123102917.3190.qmail@sources.redhat.com> (raw)


>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;
}


             reply	other threads:[~2002-01-23 10:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-23  2:36 espenlaub [this message]
2002-08-23 13:11 jsm28

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020123102917.3190.qmail@sources.redhat.com \
    --to=espenlaub@informatik.uni-ulm.de \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).