It took me several hours to try to extract a usable test-case for this issue, so I hope you will be able to make sense out of it.
The problem : compiling with current g++ 4.2, with -O2, makes the attached program loop infinitely, while it is not expected to. It does not loop with g++ 4.3 or older versions than 4.2. It also does not loop when adding -fno-strict-aliasing with g++ 4.2, or when compiling with -O only. Even more strange : it does not loop when I remove some unused bits of the program (which is why I had a hard time shrinking it down), for example unused typedefs (look for "limb2"). The relevant part of the program is a small class (MP_Float) containing an std::vector<short>, and some code around it, namely the operator_minus() function which is called, and which loops. I attach the pre-processed file, as well as the main small file so that you can see what is the relevant part of it, and decide if it is a compiler bug or an issue with my program. My program does some type conversions, which may be the source of the problem (triggering undefined behavior ?), but they seem fine to me. -- Summary: Non-deterministic bug producing a run-time infinite loop Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sylvain dot pion at sophia dot inria dot fr GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31268