When I compile the following code with gcc-4.4.0 with "-O3 -Wall" flags I get
the messages below.
Testcase has 'union' between Z and char types therefore such type conversion
should be allowed by aliasing rules.

--- error message ---
pr.C: In member function ‘Z& X::get()’:
pr.C:12: warning: dereferencing type-punned pointer will break strict-aliasing
rules

--- testcase ---
struct Z {int ii;};

struct X {
  union {
    Z objs[1];
    char bb[20];
  };
  Z& get() {
    return (*(Z*)&bb[0]); // <--- error message here
  }
};


-- 
           Summary: Erroneous aliasing rules message
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yuri at tsoft dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40560

Reply via email to