This is the mail archive of the gcc@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]

Re: aliasing warnings [patch]


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


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