The following code outputs "123.456" with no optimization or "-O1", but outputs a corrupted value when compiled with "-02" or even with "-O1 -fstrict-aliasing -fschedule-insns2".
#include <iostream> int main() { // binary representation of double value 123.456 unsigned long long ull = 0x405edd2f1a9fbe77ll; std::cout << reinterpret_cast<double &>(ull) << std::endl; } -- Summary: reinterpret_cast to different reference or pointer type is overoptimized with -O2 Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: trash at wobow dot com GCC host triplet: 2.6.24 GCC target triplet: 2.6.24 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37115