Re: strict-aliasing question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jörg Richter <Joerg.Richter@xxxxxxxxx> writes:

> I thought I have understood the aliasing-rules. But what is wrong with this:
>
> $ cat alias.cc
> #include <memory>
>
> struct Col
> {
>     short val;
> };
>
> void func()
> {
>   char arr[sizeof(Col)] __attribute__ ((aligned(__alignof__(Col))));
>   new (arr) Col;
>   ((Col*)arr)->~Col();          // line 12
> }
>
> $ /tools/pkg/gcc/4.4.1/bin/g++ -o alias.o -c alias.cc -Wall -O2
> alias.cc: In function void func():
> alias.cc:12: warning: dereferencing type-punned pointer will break
> strict-aliasing rules

The type char[] is not compatible with the type Col*.

You might think they are because of the special exception for char*, but
char[] is not char*.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux