This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing warnings [patch]
- To: Zack Weinberg <zack at bitmover dot com>
- Subject: Re: aliasing warnings [patch]
- From: Jamie Lokier <egcs at tantalophile dot demon dot co dot uk>
- Date: Wed, 13 Oct 1999 14:28:20 +0200
- Cc: egcs at egcs dot cygnus dot com
- References: <199909161637.JAA15001@zack.bitmover.com>
Zack Weinberg wrote:
> The appended patch causes warnings to be generated, in
> -fstrict-aliasing mode, when a pointer is cast to a type outside its
> alias set. char * and void * are excepted, as are casts from T to
> union containing T; the latter is warned about anyway with -pedantic.
In C++, to convert between pointers to incompatible types you have to go
through void *. In other words:
struct A * aptr = <...>;
struct B * bptr1 = (struct B *) aptr; // not ok
struct B * bptr2 = (struct B *) (void *) aptr; // ok
So you may want to add something special to handle the intermediate
void * in these cases.
The reinterpret_cast operator effectively does the void * thing:
struct B * bptr3 = reinterpret_cast<struct B *> (aptr); // ok
So it would be useful to do the warning test in reinterpret_cast too.
This doesn't need any hoops to detect an intermediate void *.
-- Jamie