This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c++/23915] New: Missing -Wstrict-aliasing warning


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


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