A template function (which swaps two values) is called in a loop in an inlined method of a template class. The number of loop iterations is a constant, so the compiler might be trying to unroll the loop.
The final assignment of the swap function is not executed after the first iteration, causing incorrect results. The problem occurs with -O2 or -O3, but not with -O. I will attach a self-contained demo program. -- Summary: bad code in template function called from template class method Product: gcc Version: 3.3.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: james_avera at yahoo dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i586-suse-linux-gnu GCC host triplet: i586-suse-linux-gnu GCC target triplet: i586-suse-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18468