[Bug c++/41874] New: Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
jyasskin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Oct 30 01:32:00 GMT 2009
$ cat test.cc
#include <new>
struct APInt {
int i;
};
int main() {
APInt I;
char Data[sizeof(APInt)];
new((void*)Data)APInt();
*(APInt*)Data = I;
}
$ g++ -O3 -Wstrict-aliasing test.cc -o /dev/null
test.cc: In function 'int main()':
test.cc:9: warning: dereferencing type-punned pointer will break
strict-aliasing rules
test.cc:9: warning: dereferencing type-punned pointer will break
strict-aliasing rules
$ g++ -v
Using built-in specs.
Target: i386-apple-darwin9
Configured with: ../gcc-4.4.1/configure --prefix=/opt/local
--build=i386-apple-darwin9 --enable-languages=c,c++,objc,obj-c++,java,fortran
--libdir=/opt/local/lib/gcc44 --includedir=/opt/local/include/gcc44
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--with-local-prefix=/opt/local --with-system-zlib --disable-nls
--program-suffix=-mp-4.4 --with-gxx-include-dir=/opt/local/include/gcc44/c++/
--with-gmp=/opt/local --with-mpfr=/opt/local
Thread model: posix
gcc version 4.4.1 (GCC)
The warning goes away if I change "*(APInt*)Data = I;" to "*(APInt*)(void*)Data
= I;" even though an extra cast through void* can't improve the situation wrt
strict-aliasing.
--
Summary: Incorrect "dereferencing type-punned pointer will break
strict-aliasing rules" warning
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jyasskin at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41874
More information about the Gcc-bugs
mailing list