This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: can't disable pointer-to-int-cast warnings


On 26 March 2011 01:02, Hargett, Matt <matt.hargett@bluecoat.com> wrote:
> Hi,
>
> We need to selectively disable int-to-pointer-cast warnings in pragmas, but these particular classes of warnings appear to be invulnerable to disabling. The following code:
>
> #include <inttypes.h>
> #pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
> #pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
>
> void f(intptr_t x)
> {
> ??????????????? (void)x;
> }
>
> int main(void)
> {
> ??????????????? char name[] = "bob";
> ??????????????? f(name);
> }
>
> Compiled with this commandline:
> gcc -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -c foo.c
>
> produces the following (approximate) output with GCC 4.3.5, 4.4.4, 4.5.1, and 4.6 RC2, regardless of optimization level:
> foo.c: In function 'main':
> foo.c:13:2: warning: passing argument 1 of 'f' makes integer from pointer without a cast [enabled by default]
> foo.c:5:6: note: expected 'intptr_t' but argument is of type 'char *'
>
>
> Trying the pragmas by themselves doesn’t disable the warnings, nor the commandline parameters by themselves, nor the both of them together.
>
> This is obviously a bug, which I will file on Monday, but we are really hoping for a workaround that is embeddable into the header file of our library.
>
> Thanks in advance!

It's not obviously a bug, those options work as documented.

Those warning options relate to casts between pointers and integers of
different sizes.  There is no cast in your example (only an implicit
conversion) and intptr_t is not a different size to a pointer.

Adding a cast (to an integer the same size as a pointer) will stop the warning:
    f((intptr_t)name);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]