https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70531
Bug ID: 70531 Summary: Turning optimisation level 2 causes the output program to go into infinite loop Product: gcc Version: 5.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: iliyabo at hotmail dot com Target Milestone: --- Created attachment 38176 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38176&action=edit Source file causing the bug While solving algorithm problems, I stumbled on a problem which I think is a bug within the g++ compiler. You can see the source code in the attachment. If I compile with g++ $(srcfile) -o output, the resulting executable works as expected. But when I turn optimisations (-O2), resulting executable goes into infinite loop and I must terminate it. This behaviour doesn't happen if I try to use clang++ (both with optimisation on and off). I am using fedora 23 with g++ version 5.3.1. If you need anything else, tell me.