Bug 24727 - type "const void *" produces a warning when promoting to "void *"
Summary: type "const void *" produces a warning when promoting to "void *"
Status: RESOLVED DUPLICATE of bug 16895
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.1
: P3 trivial
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-07 23:37 UTC by Joshua
Modified: 2005-12-07 17:09 UTC (History)
5 users (show)

See Also:
Host: Multiple
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua 2005-11-07 23:37:00 UTC
Tried this on two machines:

SunOS hornet 5.10 Generic sun4u sparc SUNW,Ultra-4
    with GCC 4.0.1
Linux numenor 2.6.13 #9 Mon Sep 19 19:03:35 PDT 2005 i686 unknown unknown GNU/Linux
    with GCC 3.3.6

The following code produces spurios warning:
/* Cut here */
int x_read(int h, void *buf, unsigned len);
int x_write(int h, const void *buf, unsigned len);

typedef int (*x_io)(int h, void *buf, unsigned len);
int blockio(int h, long long offset, void *buf, x_io action);

int bug(int h, unsigned where, void *buf)
{
        return blockio(h, (long long)where << 10, buf, x_write);
}
/* Cut here */
sample.c: In function `bug':
sample.c:9: warning: passing arg 4 of `blockio' from incompatible pointer type
Comment 1 Andreas Schwab 2005-11-08 00:07:42 UTC
The warning is correct.  The type of x_write is incompatible with x_io, because "const void *" is incompatible with "void *".  Argument promotion does not come into play here.
Comment 2 Joshua 2005-11-08 04:25:20 UTC
Aren't function arguments contravariant rather than covariant?
Comment 3 Andrew Pinski 2005-11-08 04:34:24 UTC
No, in C, these are two different function types.
Comment 4 Andrew Pinski 2005-12-07 17:08:54 UTC
Reoepening to ...
Comment 5 Andrew Pinski 2005-12-07 17:09:10 UTC
To Close as a dup of bug 16895.

*** This bug has been marked as a duplicate of 16895 ***