This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/23915] New: Missing -Wstrict-aliasing warning
- From: "larschri at pvv dot ntnu dot no" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Sep 2005 12:01:20 -0000
- Subject: [Bug c++/23915] New: Missing -Wstrict-aliasing warning
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I get warning when compiling the following program as C, but not as C++. I have
experienced that such casts can fail for both C and C++ programs when running
with option -O2. See also [Bug c/23913].
int main() {
float f = 4.5;
int i = *((int*)&f);
(void)i;
return 0;
}
$ g++ -Wstrict-aliasing -O2 foo.cpp
$ g++ --version
g++ (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc -Wstrict-aliasing -O2 foo.c
cast-bug.c: In function 'main':
cast-bug.c:5: warning: dereferencing type-punned pointer will break
strict-aliasing rules
--
Summary: Missing -Wstrict-aliasing warning
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: larschri at pvv dot ntnu dot no
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23915